layout_weight

layout_weight属性是LinearLayout子view的专有属性, 用来说明 当LinearLayout 按照各子view的要求 分配给各子view大小 之后,如果还有剩余的空间,如何将剩余空间分配给子view。就是子view如何瓜分LinearLayout的剩余空间。

Google的文档推荐如果使用了这个属性,那么子view的layout_width(或者layout_height,这个取决于LinearLayout的orientation)应该写为0dp,原因是为了提高效率

In order to improve the layout efficiency when you specify the weight, you should change the width of the EditText to be zero (0dp). Setting the width to zero improves layout performance because using "wrap_content" as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.

我想说的重点是layout_weight说明的是“剩余空间”而对子view要求的空间(即layout_width的属性)无效,如果我们想等分LinearLayout的空间(不是剩余空间)那么各子view要求的空间也应该是一样的, 不然在分配剩余空间之前, 就已经不等分了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值