android:layout_weight attribute.

本文介绍了在布局设计中如何使用权重属性来分配剩余空间。通过设置不同视图的权重值,可以实现灵活的空间分配,例如一个视图占据三分之二的空间而另一个占据三分之一。权重默认为0,若仅设置一个视图的权重大于0,则该视图会填充剩余的所有空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The weight value is a number that specifies the amount of remaining space each view should consume, relative to the amount consumed by sibling views. This works kind of like the amount of ingredients in a drink recipe: "2 parts soda, 1 part syrup" means two-thirds of the drink is soda. For example, if you give one view a weight of 2 and another one a weight of 1, the sum is 3, so the first view fills 2/3 of the remaining space and the second view fills the rest. If you add a third view and give it a weight of 1, then the first view (with weight of 2) now gets 1/2 the remaining space, while the remaining two each get 1/4.

The default weight for all views is 0, so if you specify any weight value greater than 0 to only one view, then that view fills whatever space remains after all views are given the space they require.

所有views的weight默认值是0,如果只给其中一个view设置了大于0的值,那么,这个view将占满其他view所需要space剩余的所有空间.

这个用法,就是填充剩余的空间。类似分区的一些layout里面的center。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值