【发布时间】:2014-03-26 06:06:04
【问题描述】:
我是 Android 新手,我有以下任务。
如果文本太长,我想将彼此相邻的三个 TextView 用省略号对齐。目前我正在使用下面的代码来对齐我的 TextView 彼此相邻,但我的问题是如果文本太长,下面的代码没有放置省略号。我有一些技巧可以同时使用here 中的toleftof 和torightof,但在我的情况下,它会像here 中提到的那样循环依赖。
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@+id/reminderText">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/noteTagOne"
android:ellipsize="end"
android:singleLine="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/noteTagTwo"
android:ellipsize="end"
android:singleLine="true"
android:layout_toRightOf="@+id/noteTagOne"
android:layout_marginLeft="5sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/noteTagThree"
android:layout_toRightOf="@+id/noteTagTwo"
android:ellipsize="end"
android:singleLine="true"
android:layout_marginLeft="5sp"/>
</RelativeLayout>
我想输出为,
Tag1... Tag2... Tag3...
基本上,我想要一些想法,无论是在 xml 中我可以实现这一点还是需要以编程方式实现它,因为 TextView 文本是动态的,我无法修复 maxLength,有时可能只存在单个标签,那时它应该采用全文。
注意:我正在 Xamarin 中使用 C# 开发 Android 项目。
添加的代码是针对上面突出显示的部分。我修复了标签图标和文本的重叠。现在只有两个问题。
1) 最后一个标签与右对齐图像重叠。 2)如果TextView文本很短,标签之间会显示间隙
如何解决?
【问题讨论】:
-
使用
LinearLayout并将orientation设置为水平并具有weightSum = "3"。现在在这个LinearLayout中保留三个TextViews,每个TextView具有layout_weight="1"和layout_width="0dp"... -
谢谢,工作得很好,但在这三个 TextView 之前,我有一个 ImageView,如果我添加了,第一个标签不会变成椭圆形...
-
imageview 占用的空间是否应该等于单个 TextView 的空间?
-
是的,它的大小是 16X16,但是如果我在 LinearLayout 中添加 TextView 意味着图像变得太宽,通过添加它与第一个 TextView 文本重叠。
-
如果您使用的是
RelativeLayout,那么您的LinearLayout包含TextViews 应该在右侧链接图像并左侧到文件夹图像
标签: android android-relativelayout