国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android中的android:layout_weight使用詳解

2020-04-11 12:09:45
字體:
來源:轉載
供稿:網友
在使用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即可實現。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平阴县| 贵定县| 大港区| 陇南市| 苍南县| 柳河县| 孝义市| 隆林| 淮北市| 宜宾县| 天津市| 仪征市| 扎囊县| 巴楚县| 香格里拉县| 贞丰县| 阜新| 周至县| 新龙县| 星座| 大荔县| 林口县| 建德市| 澎湖县| 封丘县| 富宁县| 富裕县| 遂溪县| 深水埗区| 瑞金市| 临沭县| 阳西县| 定西市| 沙雅县| 岚皋县| 福泉市| 侯马市| 炎陵县| 阳曲县| 平远县| 尖扎县|