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

首頁 > 系統 > Android > 正文

詳解android layout 按比例布局的代碼

2020-02-21 17:35:34
字體:
來源:轉載
供稿:網友

由于Android的復雜性,在寫程序的時候經常會遇見一些難題,也可能會遇見處理不了的問題,下面是武林技術頻道小編詳解android layout 按比例布局的代碼,一起進入下文了解一下吧!

為了創建比例大小的子View,可以將LinearLayout的寬度和高度設為fill_parent, 而將子View的寬度或是高度設為0,然后為子View設置不同權重(weight) ,這樣子View的大小就會權值成比例。

本例使用橫向LinearLayout,LinearLayout的android:layout_width=”match_parent”,表示將使用整個屏幕寬度。

對于LinearLayout的幾個子View,將它們的寬度都定義為0,android:layout_width=”0dip”,然后使用layout_weight 為每個View指定寬度比例,本例為每個TextView都使用了相同的權值,因此四個TextView將會有相同的寬度。這樣對于那些顯示文字比較長的TextView的高度就變為多行。

復制代碼 代碼如下:

android:layout_width=”match_parent”
android:layout_height=”wrap_content”>

?

android:background=”@drawable/red”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_small”/>

android:background=”@drawable/green”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_big”/>

android:background=”@drawable/blue”
android:layout_width=”0dip”
android:layout_height=”match_parent”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_small” />

android:background=”@drawable/yellow”
android:layout_width=”0dip”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:text=”@string/linear_layout_7_wrap”/>

以上代碼都是武林技術頻道小編詳解android layout 按比例布局的代碼,希望對大家的學習有一定的幫助!

?

?

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 寻甸| 江门市| 邢台市| 招远市| 郸城县| 会昌县| 印江| 康定县| 静安区| 得荣县| 宜兰县| 鱼台县| 准格尔旗| 云南省| 卫辉市| 洛隆县| 甘肃省| 碌曲县| 金昌市| 双牌县| 宁安市| 五河县| 长白| 青海省| 抚松县| 二连浩特市| 绥德县| 周宁县| 太白县| 陆良县| 湟中县| 哈巴河县| 靖江市| 荥阳市| 鲁甸县| 衡山县| 包头市| 万宁市| 纳雍县| 调兵山市| 长宁县|