1、当控件的属性android:layout_width="fill_parent"时,布局文件设置的android:layout_weight成反比关系。
如:button1 设置android:layout_weight="1",button2设置 android:layout_weight="2",则button1和button的长度比是2:1,成为反比。
2、当控件的属性android:layout_width="wrap_content"时,布局文件设置的android:layout_weight成正比关系。
如:button1 设置android:layout_weight="1",button2设置 android:layout_weight="2",则button1和button的长度比是1:2,成为正比。
3、如果一行中有2个组件,想要设置第一个组件固定大小,第二个组件填充所有的空间,可以设置第二个组件为
android:layout_width="fill_parent"和android:layout_weight="1"。
理解Android布局权重
本文详细解释了在Android布局中如何使用android:layout_weight属性来控制控件的宽度比例。特别是针对'fill_parent'和'wrap_content'两种不同场景下,布局权重属性的不同表现方式进行了阐述,并给出实际应用示例。
4164

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



