我有列表视图。行有2个(以及更多的将来)文本视图。我的目标是,如果第一个文本太长,则应显示椭圆,但第二个文本视图应始终可见。我临时通过列(权重+文本视图的百分比权重)解决了这个问题。但我的目标是:当文本短时,第二个文本视图应该显示在第一个旁边(参见第一个附加屏幕,它是假的 - 由第一个文本视图的硬编码最大宽度创建)。问题是,当第一个文本太长时,第二个文本就会消失。我已经尝试了很多配置与linearlayout,relativelayout,sublayouts等,但最后我卡住了。任何想法?这是简单的XML为行:Android - 长椭圆textview封面下一个textview
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="Some very very long long long long long long long"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#C03518"
android:text="10"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
这是RelativeLayout的代码不工作过:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/TextView01"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some very very long long long long long long long"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/TextView02"
android:layout_toRightOf="@id/TextView01"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#C03518"
android:text="10"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
问候
尝试相对布局和android:layout_toRightOf = “idOftheLeftTextView” 将可能ellipsize它为您服务! – Pavlos
我同意上面的评论,但是这种方法要求第二个TextView具有'layout_alignParentRight =“true”'。 – Sam
我也尝试过使用RelativeLayout,但结果相同。我用relativelayout例子编辑了第一篇文章。也许我可以在运行时计算它吗?例如计算第二个文本的宽度,然后设置为第一个文本的最大宽度的区别 – Dibo