对android的layout_weight属性的理解

今天官网上看见了一个对layout_weight的评论(在下面),

还看了这篇博客http://lovezhou.iteye.com/blog/827881

终于基本理解这个属性怎么用了。

个人认为设置layout_weight属性时,若父控件为vertical,应该设置子控件高度应该为wrap_content,

这样才符合google对layout_weight的定义,此时,layout_weight值越大,所占剩余空间也越大,

同时也比较符合权重平常的意思,即权重越大越重要。

统一这样设置也有利于开发者对layout_weight属性的理解,从我在网上查得许多资料来看,讲的并不精确!

 

 

layout_wieght gives different results depending on whether or not the
width/height value set in the XML is 0 or not.
What layout_weight does is: a view is allowed to have the specified size
(e.g. wrap_content or 100dp, or 200px, or 0) and then any unused space in
the parent is distrubuted according to the weights.
The practical implicaiton of this is:
- If you want to use a fixed fraction of the parent view, then use
layout_width="0px" and layout_weight="some value". This makes the view start
out 0px width, and then take up more space.
- If you set layout_width="wrap_content", and layout_weight="some value", it
means, measure the view (wrap_content), make it that size, and then add more
space if available.
In the first case, if you have two views with equal weight, they will end up
equally sized.
In the second case, if the two views have different sizes due to
wrap_content (e.g. one is "foo", the other "Android (r) Gingerbread 3.0"),
they will end up differently sized even with equal layout_weight values.

 

google的翻译----

layout_wieght给出不同的结果,取决于是否
在XML中设置的宽度/高度值是0或没有。
layout_weight确实的是:一种意见是允许指定的大小
(例如wrap_content或100dp,或200像素,或0),然后在任何未使用的空间
父distrubuted根据权重。
本实用implicaiton是:
- 如果你想使用父视图中的固定部分,然后使用
layout_width=0px”和layout_weight=“一定的价值。”这使得查看启动
出0px宽度,然后会占用更多空间。
- 如果你设置layout_width=wrap_content”,并layout_weight=“一定的价值”,它
手段,措施的看法(wrap_content),它的大小,然后添加更多
如果可用空间。
在第一种情况,如果你有两个同等重量的意见,他们将结束
同样大小的。
在第二种情况下,如果这两种观点有不同的大小因
wrap_content(例如,一个是“富”,其他“Android的姜饼3.0(R)”)
他们最终会不同,甚至与平等的layout_weight值大小。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值