我有一个ListView
显示两个TextView
的,如下所示:
| Each row | has the |
| same width | as the row |
| before it | like this |
但是我想做这样的事情:
| Each left column | uses |
| as much space | as it |
| needs | like this |
可以仅使用XML来完成吗?我曾尝试修改此解决方案,但无法正常工作。
您应该在中包装文字视图RelativeLayout
。指定android:layout_width="wrap_content"
了两者,android:layout_alignParentLeft="true"
并android:layout_alignParentRight="true"
为左,右分别TextViews。分别设置android:gravity="left"
和android:gravity="right"
但在这种情况下,长文本可能会重叠
另一种选择是使用layout_weight
:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left"
android:text="some text"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="right"
android:text="text"/>
</LinearLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句