8月10日

公司同事赵磊加班,今天就加了,周六日还加。唉。害羞啊,我就是搞不定。

晚上喊了个人来帮我搞代码,分分钟拿下,weight真是一个重要的属性。

还有代码中的警告以后一定要多多注意啊。

线性布局通常支持分配一个权重值给每一个孩子。这个属性标识了一个view的重要性,

并且允许它填充任意的在父view中剩余的空间。子view们可以指定一个int型的权重值,

然后在view group中剩余的空间就会,按照他们声明的权重值按比例分配。

默认的权重值是0.比如说,如果有三个盒子其中的两个声明权重值为1,剩下那个声明为0.

那么剩下那个即第三个盒子就不会扩展,而只会占据它被来需要的空间。另外两个会扩展

填充剩余的空间,在这三个盒子的大小被测量好之后。

如果第三个盒子把权重值从0改为2.那么现在它就被声明为更重要了比起另外两个盒子,

所有它会分配到剩余空间的一半,而那两个则会平分剩余的空间。

LinearLayout  also supports assigning a weight to individual children.

This attribute assigns an "importance" value to a view, and allows it to expand to fill any remaining space in the parent view.

Child views can specify an integer weight value, and then any remaining space in the view group is assigned to children

in the proportion of their declared weight. Default weight is zero.

For example, if there are three text boxes and two of them declare a weight of 1,

while the other is given no weight (0), the third text box without weight will not grow and will only occupy the area required by its content.

The other two will expand equally to fill the space remaining after all three boxes are measured.

If the third box is then given a weight of 2 (instead of 0), then it is now declared "more important" than both the others,

so it gets half the total remaining space, while the first two share the rest equally.

posted on 2012-08-11 00:04  lightman_21  阅读(120)  评论(0)    收藏  举报

导航