拥有一个 TextView
,它的宽度不应该超过其父容器宽度的1/3。如果它的宽度小于父容器的1/3,则应具有 wrap_content
的行为。它的水平兄弟总是在它旁边开始。
尝试了以下方法,它总是硬性地划分为1/3和2/3,因此如果text1的空间小于1/3,则TextView
two将无法紧邻其旁边。
将LinearLayout
更改为RelativeLayout
,然后 android:layout_weight="n"
就不起作用了。
基本上,需要定义宽度为 wrap_content
,并且 maxWidth
不超过1/3。
有什么建议吗?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="end"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:singleLine="true"
android:ellipsize="end"
android:layout_weight="2"
/>
</LinearLayout>