【发布时间】:2010-09-24 08:03:38
【问题描述】:
我想让两个TextView 元素并排出现(在列表项中),一个左对齐,一个右对齐。比如:
|<TextView> <TextView>|
(| 代表屏幕的末端)
但是,左侧的TextView 的内容可能太长而无法在屏幕上显示。在这种情况下,我想让它变成椭圆形,但仍然显示整个右边TextView。比如:
|This is a lot of conte...<TextView>|
我对此进行了多次尝试,同时使用LinearLayout 和RelativeLayout,我想出的唯一解决方案是使用RelativeLayout 并在左侧放置marginRight TextView big足以清除正确的TextView。但是,正如您可以想象的那样,这并不是最佳选择。
还有其他解决方案吗?
最终,LinearLayout 解决方案:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:inputType="text"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0"
android:layout_gravity="right"
android:inputType="text"
/>
</LinearLayout>
老,TableLayout 解决方案:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:shrinkColumns="0"
>
<TableRow>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
/>
<TextView android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="none"
android:gravity="right"
/>
</TableRow>
</TableLayout>
【问题讨论】:
-
我也想对答案投票。 :)