android:layout_weight作用介绍
2014-01-05 00:28
399 查看
一下内容来自google android developers上的介绍:
supports assigning a weight to individual children with the
This attribute assigns an "importance" value to a view in terms of how much space is should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a 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 fields and two of them declare a weight of 1, while the other is given no weight, the third text field 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 fields are measured. If the third field 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.
更详细的的使用方法可以参考以下链接:
LinearLayoutalso
supports assigning a weight to individual children with the
android:layout_weightattribute.
This attribute assigns an "importance" value to a view in terms of how much space is should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a 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 fields and two of them declare a weight of 1, while the other is given no weight, the third text field 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 fields are measured. If the third field 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.
layout_weight用于给一个线性布局中的每个视图的重要度赋值。所有的视图都有一个layout_weight值,默认值为零,表示需要显示多大的视图就占据多大的屏幕空间。若给一个视图赋一个高于零的值,则会将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight值以及该值在当前屏幕布局的整体layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。 举个例子:比如说我们在水平方向上有一个文本标签和两个文本编辑元素。该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。 如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个文本编辑元素其中第一个的layout_weight值设置为1,而第二个的设置为2,则剩余空间的三分之二分给第一个,三分之一分给第二个(数值越小,重要度越高)。
更详细的的使用方法可以参考以下链接:
The
use of layout_weight with Android layouts:http://www.chess-ix.com/blog/the-use-of-layout_weight-with-android-layouts/
相关文章推荐
- android中layout的layout_weight属性介绍
- Android视图控件属性layout_weight的作用
- Android layout_weight 属性使用介绍
- android LinearLayout android:layout_weight 作用,固定比例
- Android视图控件属性layout_weight的作用
- android:layout_weight详细分析介绍
- android LinearLayout android:layout_weight 作用,固定比例
- Android 布局之LinearLayout 子控件weight权重的作用详析
- ANDROID布局中LAYOUT_WEIGHT的作用
- Android 布局之LinearLayout 子控件weight权重的作用详析
- Android布局中Layout_weight属性详细介绍
- LinearLayout中android:layout_weight的作用
- 安卓中linearLayout下android_layout.weight的属性的详细介绍
- LinearLayout中android:layout_weight的作用
- Android 布局之LinearLayout 子控件weight权重的作用详析
- Android 布局之LinearLayout 子控件weight权重的作用详析
- android:layout_weight的作用
- Android 布局之LinearLayout 子控件weight权重的作用详析
- android 布局中的layout_weight的作用
- Android 布局之LinearLayout 子控件weight权重的作用详析(转)