最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中的android:layout_weight使用詳解

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

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

<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占據屏幕寬度的三分之二,而Button2占據三分之一,如下圖所示:
 
如果兩個Button的layout_width都設置成wrap_content,則情況剛好相反。Button1占三分之一,Button2占三分之二,如下圖所示:
 
layout_weight在使用LinearLayout設計復雜的布局時還是挺有用處的,例如,在水平的線性布局中,你要分足夠的空間給控件1,剩下的空間則分配給控件2,則只要設置控件1的layout_width設置為wrap_content,不用設置layout_weight,而在控件2中,設置layout_width為fill_parent,layout_weight為1即可實現。

相關文章

最新評論

平凉市| 屏东县| 紫阳县| 墨脱县| 三明市| 桑日县| 梨树县| 绍兴市| 尉氏县| 蒙山县| 仲巴县| 迭部县| 灵山县| 涡阳县| 河曲县| 新巴尔虎右旗| 体育| 关岭| 冕宁县| 安阳市| 徐汇区| 敖汉旗| 思茅市| 铜陵市| 昭苏县| 江永县| 新田县| 棋牌| 祁阳县| 论坛| 长岛县| 金湖县| 绵竹市| 海城市| 页游| 大余县| 寿阳县| 南充市| 娄烦县| 宁安市| 凤冈县|