欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中的android:layout_weight使用詳解

 更新時(shí)間:2013年06月16日 16:20:07   作者:  
layout_weight的作用是設(shè)置子空間在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,則控件越重要,下面為大家介紹下具體的使用方法
在使用LinearLayout的時(shí)候,子控件可以設(shè)置layout_weight。layout_weight的作用是設(shè)置子空間在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,則控件越重要。若不設(shè)置layout_weight則默認(rèn)比重為0。

如果在一個(gè)LinearLayout里面放置兩個(gè)Button,Button1和Button2,Button1的layout_weight設(shè)置為1,Button2的layout_weight設(shè)置為2,且兩個(gè)Button的layout_width都設(shè)置為fill_parent。
復(fù)制代碼 代碼如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Button2"/>
</LinearLayout>

則Button1占據(jù)屏幕寬度的三分之二,而B(niǎo)utton2占據(jù)三分之一,如下圖所示:
 
如果兩個(gè)Button的layout_width都設(shè)置成wrap_content,則情況剛好相反。Button1占三分之一,Button2占三分之二,如下圖所示:
 
layout_weight在使用LinearLayout設(shè)計(jì)復(fù)雜的布局時(shí)還是挺有用處的,例如,在水平的線(xiàn)性布局中,你要分足夠的空間給控件1,剩下的空間則分配給控件2,則只要設(shè)置控件1的layout_width設(shè)置為wrap_content,不用設(shè)置layout_weight,而在控件2中,設(shè)置layout_width為fill_parent,layout_weight為1即可實(shí)現(xiàn)。

相關(guān)文章

最新評(píng)論