布局管理器要点

来源:互联网 发布:js如何遍历数组 编辑:程序博客网 时间:2024/06/14 21:41
线性布局管理器的layout-weight

layout-weight就是控件所占空间的比例,比重。layout_weight是给LinearLayout的子控件使用的,其他布局无法使用。

正确的用法为:
在LinearLayout是垂直的时候,layout_weight将控制子控件的高度占总控件的百分比,这时子控件的layout_height要为0dp.
在LinearLayout是水平的时候,layout_weight将控制子控件的宽度占总控件的百分比,这时子控件的layout_width要为0dp

SDK讲解:

我们如果在某个方向上使用了weight ,那么我们必须在对应的方向上将width设置为0dp. 它告诉了我们设置为0dp是因为使用weight,系统是采用了另外一套计算占用空间大小的算法的.(the weight value requires another width calculation to fill the remaining space.)

原创粉丝点击