Android:相对布局中的多个文本视图需要省略号
我是Android新手,我有以下任务 如果文本太长,我想用省略号对齐彼此相邻的三个文本视图。目前我正在使用下面的代码将我的文本视图相邻对齐,但我的问题是如果文本太长,下面的代码就不会放省略号。我得到了一些技巧,可以同时使用Android:相对布局中的多个文本视图需要省略号,android,android-relativelayout,Android,Android Relativelayout,我是Android新手,我有以下任务 如果文本太长,我想用省略号对齐彼此相邻的三个文本视图。目前我正在使用下面的代码将我的文本视图相邻对齐,但我的问题是如果文本太长,下面的代码就不会放省略号。我得到了一些技巧,可以同时使用toleftof和torightoffrom,但在我的例子中,它将变成前面提到的循环依赖 基本上,我想要一些想法,无论是在xml中我可以实现这一点,还是需要以编程方式实现这一点,因为TextView文本是动态的,我无法修复maxLength,有时可能只存在一个标记,当时应该是全
toleftof
和torightof
from,但在我的例子中,它将变成前面提到的循环依赖
基本上,我想要一些想法,无论是在xml中我可以实现这一点,还是需要以编程方式实现这一点,因为TextView文本是动态的,我无法修复maxLength,有时可能只存在一个标记,当时应该是全文
注意:我正在使用Xamarin中的C#开发Android项目
添加的代码用于上面突出显示的部分。我修复了tagsicon和文本的重叠。现在只有两个问题
1) 最后一个标记与右对齐的图像重叠。
2) 如果TextView文本较短,则标签之间会显示间隙
如何修复它?使用这个安卓:ellipsize=“marquee”它会工作的
android:ellipsize="marquee"
或
试试这个解决方案
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >
<TextView
android:id="@+id/noteTagOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag111111111111111111"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/noteTagTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="@+id/noteTagOne"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag2222222222222222"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/noteTagThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="@+id/noteTagTwo"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag3333333333333333"
android:textAppearance="?android:attr/textAppearanceLarge" />
但是使用android:ellipsize=“marquee”,我是否能够在最后得到点(…)?基本上,我不希望省略的文本可以滚动使用
LinearLayout
并将方向设置为水平并具有weightSum=“3”
。现在将三个TextView
s放在LinearLayout
中,每个TextView
都有layout\u weight=“1”
和layout\u width=“0dp”
…谢谢,工作得很好,但是在这三个TextView之前我有一个图像视图,如果我加上它,第一个标记没有被省略…是不是imageview应该占用与单个TextView相等的空间?是的,它的大小是16X16,但如果我将LinearLayout和TextView means一起添加到内部,则图像会变得太宽,因为它的外部会与第一个TextView文本重叠。如果您使用的是RelativeLayout
,然后你的LinearLayout
包含TextView
s的内容应该是右链接图像,左链接文件夹图像,但是否可以在不固定宽度的情况下实现这一点,因为如果文本很小,标签之间会显示间隙,看起来很奇怪……请让我知道。如果我是聊天室,笑脸图标ellipsize不起作用
android:ellipsize="marquee"
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >
<TextView
android:id="@+id/noteTagOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag111111111111111111"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/noteTagTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="@+id/noteTagOne"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag2222222222222222"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/noteTagThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="@+id/noteTagTwo"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag3333333333333333"
android:textAppearance="?android:attr/textAppearanceLarge" />