日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LinearLayout(线性布局)

發(fā)布時間:2024/4/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LinearLayout(线性布局) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
要點:

android:orientation="vertical"垂直線性布局,"horizontal"水平線性布局

android:gravity="top"(buttom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal)控制布局中控件的對齊方式。如果是沒有子控件的控件設(shè)置此屬性,表示其內(nèi)容的對齊方式,比如說TextView里面文字的對齊方式;若是有子控件的控件設(shè)置此屬性,則表示其子控件的對齊方式,gravity如果需要設(shè)置多個屬性值,需要使用“|”進行組合

android:gravity 與 android:layout_gravity的區(qū)別
android:gravity是指定本元素的子元素相對它的對齊方式。
android:layout_gravity是指定本元素相對它的父元素的對齊方式。

android:layout_weight="1"通過設(shè)置控件的layout_weight屬性以控制各個控件在布局中的相對大小,線性布局會根據(jù)該控件layout_weight值與其所處布局中所有控件layout_weight值之和的比值為該控件分配占用的區(qū)域。在水平布局的LinearLayout中有兩個Button,這兩個Button的layout_weight屬性值都為1,那么這兩個按鈕都會被拉伸到整個屏幕寬度的一半。如果layout_weight指為0,控件會按原大小顯示,不會被拉伸;對于其余l(xiāng)ayout_weight屬性值大于0的控件,系統(tǒng)將會減去layout_weight屬性值為0的控件的寬度或者高度,再用剩余的寬度或高度按相應(yīng)的比例來分配每一個控件顯示的寬度或高度。

如:


代碼如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".LinearLayoutActivity" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:background="#aa0000"android:gravity="center_horizontal|center_vertical"android:text="第一列"android:textSize="15sp" ></Button><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:background="#00aa00"android:gravity="center_horizontal"android:text="第二列"android:textSize="15sp" ></Button><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:background="#0000aa"android:gravity="center|bottom"android:text="第三列"android:textSize="15sp" ></Button><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:background="#aaaa00"android:gravity="bottom"android:text="第四列"android:textSize="15sp" ></Button></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:orientation="vertical" ><Buttonandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="bottom"android:text="第1行"android:textSize="15sp" ></Button><Buttonandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="bottom"android:text="第2行"android:textSize="15sp" ></Button><Buttonandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="bottom"android:text="第3行"android:textSize="15sp" ></Button><Buttonandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="bottom"android:text="第4行"android:textSize="15sp" ></Button></LinearLayout></LinearLayout>

總結(jié)

以上是生活随笔為你收集整理的LinearLayout(线性布局)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。