android:layout_weight 属性对于组件长度的影响

本文探讨了在Android布局中使用LinearLayout时,如何通过android:layout_weight属性来调整Button组件的宽度分配。当Button的宽度设置为fill_parent时,所有Button的宽度相等;而设置为wrap_content时,各Button的宽度依据内容自动调整。

<LinearLayout android:id="@+id/lnLayoutBottom" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:layout_weight="1" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:layout_weight="1" android:enabled="false"/> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:layout_weight="1" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:layout_weight="1" android:enabled="false"/> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:layout_weight="1" android:enabled="false"/> </LinearLayout>

如果 五个Button的android:layout_width 属性 设置为 "fill_parent" 则 在android:layout_weight 的影响下, 起五个button的长度将相等,

如果设置为 wrap_content , 则其长度不等。。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值