注意:上一级控使用件weightSum时,子项控件的android:layout_height设置为0dp,否则分割不生效:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="25"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="18"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
本文介绍在使用LinearLayout时如何正确配置布局权重属性以实现灵活的界面布局。特别指出当父控件设置了weightSum属性时,子控件的layout_height应当设置为0dp,才能确保权重按预期分配。
4121

被折叠的 条评论
为什么被折叠?



