有一個TextView
,其寬度不應超過其父寬度的1/3。如果其寬度小於父級的1/3,則應具有wrap_content
行爲。它的水平兄弟會始終在它旁邊開始。如何設置文本視圖寬度wrap_content但限制爲父寬度的三分之一
試過後,它總是有1/3和2/3的硬切,所以如果text1的空間少於1/3,TextView
兩個不會在它旁邊開始。
變化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>
我不希望它成爲永遠的1/3,但最多到1/3,應當允許小於1/3,兄弟應該在它旁邊不空間。 – lannyf
查看更新的答案... –
謝謝馬克!如果在xml中無法實現,您的答案將是一個。 – lannyf