要想使LinearLayout布局中的每个子控件自动设置为相同大小,并均匀分布,可以在布局文件中设置layout_weight参数的值一致。
示例代码如下:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/txt_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/txt_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
本文介绍如何使用LinearLayout布局中的layout_weight属性使子控件自动设置为相同大小并均匀分布。通过设置layout_weight值相等,可以轻松实现子元素的平均分配。
745

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



