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

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



