比如在一個線性布局中,線性布局的寬度為match_parent,其有兩個子View,子View的寬度都不確定,第二個View排在第一個View后面,如果第一個View的寬度過高,會將第二個布局頂出去,那么有什么方式或者辦法確保第二個View的正常顯示?
uj5u.com熱心網友回復:
使用maxWidth,設定最大寬度uj5u.com熱心網友回復:
設定layout_weigth就可以了呀uj5u.com熱心網友回復:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="長文本"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="長文本"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
uj5u.com熱心網友回復:
設定第一個TextView權重layout_weight = "1",寬度layout_width="0dp"。你可以把權重當成是相對百分比,會占用父布局剩余控制元件的百分比,如果你希望兩個TextView,各占父布局的50%,則第二個TextView的權重layout_weight = "1",寬度layout_width="0dp"。即可,多用你就會了。轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/203918.html
標籤:Android
