Android layout layout_weight属性理解

来源:互联网 发布:萝卜游侠网络 编辑:程序博客网 时间:2024/06/07 05:34

一,android layout属性介绍:

Android有4种Layout:FrameLayout,LinearLayout,TableLayout,RelativeLayout。

放入Layout中进行排布的View的XML属性:
4种Layout中Item所共有的XML属性:
(1)layout_width
(2)layout_height
(3)layout_marginLeft
(4)layout_marginTop
(5)layout_marginRight
(6)layout_marginBottom
(7)layout_gravity

FrameLayout中的Item就具有这些属性。
对于LinearLayout还会有
(8)layout_weight

TableLayout的行TableRow是一个横向的(horizontal)的LinearLayout。

RelativeLayout有16个align相关的XML属性。
(9)layout_above
(10)layout_alignBaseline
(11)layout_alignBottom
(12)layout_alignLeft
(13)layout_alignParentBottom
(14)layout_alignParentLeft
(15)layout_alignParentRight
(16)layout_alignParentTop
(17)layout_alignRight
(18)layout_alignTop
(19)layout_below
(20)layout_centerHorizontal
(21)layout_centerInParent
(22)layout_centerVertical
(23)layout_toLeftOf
(24)layout_toRightOf

 

(1)和(2)用来确定放入Layout中的View的宽度和高度:它们的可能取值为fill_parent,wrap_content或者固定的像素值。
(3)(4)(5)(6)是放入Layout中的View期望它能够和Layout的边界或者其他View之间能够相距一段距离。
(7)用来确定View在Layout中的停靠位置。
(8)用于在LinearLayout中把所有子View排布之后的剩余空间按照它们的layout_weight分配给各个拥有这个属性的View。
(9)到(24)用来确定RelativeLayout中的View相对于Layout或者Layout中的其他View的位置。

二,layout_weight属性介绍

该属性一般都应用在LinearLayout中,在控件的layout_width值为fill_parent的时候,多个设置了wight属性的控件,weight的值越小,其站的控件越大。如果width值为

wrap_content,则weight的值越小,站的控件越就越小。

但是在width值为wrap_content的时候,首先要保证控件的显示,weight分配的空间是在除了控件wrap_content所占空间外剩余的空间里按比例分配的。


原创粉丝点击