对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_content100dp,或200像素0),然后任何未使用的空间
distrubuted根据权重
实用implicaiton
-如果你想使用父视图中固定部分,然后使用
layout_width=0pxlayout_weight=“一定的价值这使得查看启动
0px宽度,然后会占用更多空间
-如果你设置layout_width=wrap_content,并layout_weight=“一定的价值”,它
手段,措施的看法wrap_content它的大小然后添加更多
如果可用空间
在第一种情况如果你有两个同等重量意见他们结束
同样大小的
在第二种情况下如果这两种观点有不同的大小
wrap_content(例如,一个其他“Android的姜饼3.0(R)
他们最终会不同甚至与平等layout_weight大小

你可能感兴趣的:(android)