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

Android UI組件LinearLayout線性布局詳解

 更新時(shí)間:2016年08月18日 15:03:00   作者:qq_27630169  
這篇文章主要為大家詳細(xì)介紹了AndroidUI組件LinearLayout線性布局,具有一定的實(shí)用性,感興趣的小伙伴們可以參考一下

LinearLayout 線性布局,該布局的繼承關(guān)系:

這里寫(xiě)圖片描述 

1. 什么是線性布局
通俗的說(shuō)感覺(jué)起來(lái)和線有關(guān),參照線的特點(diǎn),有么是橫向的,要么是豎向的。
LinearLayout是線性布局控件,它包含的子控件將以橫向或豎向的方式排列(通過(guò)android:orientation屬性來(lái)控制),按照相對(duì)位置來(lái)排列所有的widgets或者其他的containers,超過(guò)邊界時(shí),某些控件將缺失或消失
2. 線性布局常用基本屬性
- android:id
- android:orientation
- android:layout_height
- android:layout_width
- android:gravity
- android:layout_gravity
- android:background
- android:layout_margin:
- android:padding
- android:weightSum
- android:layout_weight
- android:baselineAligned
3. 常用屬性值介紹:
android:id:
這是布局的唯一標(biāo)識(shí)ID
android:orientation:他表示的是這個(gè)線性布局是采用橫向還是縱向布局,通常來(lái)說(shuō)只有兩個(gè)值:
1. android:orientation=”vertical”表示采用縱向的布局方式,所有在當(dāng)前布局中添加的所有控件都依次按豎向排列

這里寫(xiě)圖片描述 

2. android:orientation=”horizontal”表示采用橫向的布局方式,所有在當(dāng)前布局中添加的所有控件都依次按橫向排列(默認(rèn)水平)

這里寫(xiě)圖片描述

android:layout_height: 表示當(dāng)前線性布局的高度

4. android:layout_height="match_parent"  (表示高度占滿(mǎn)整個(gè)屏幕)
5. android:layout_height="wrap_content" (表示高度根據(jù)其包含的控件自適應(yīng)調(diào)整)
6. android:layout_height="30dp"(自定義設(shè)置高度,通常單位為dp)

android:layout_width: 表示當(dāng)前線性布局的寬度

7. android:layout_width="match_parent"  (表示寬度占滿(mǎn)整個(gè)屏幕)
8. android:layout_width="wrap_content" (表示寬度根據(jù)其包含的控件自適應(yīng)調(diào)整)
9. android:layout_width="30dp"(自定義設(shè)置寬度,通常單位為dp)

android:gravity: 表示所有包含在當(dāng)前布局中的所有控件采用某種方式對(duì)齊(默認(rèn)左對(duì)齊)

這里寫(xiě)圖片描述
這里寫(xiě)圖片描述 

從上依次往下為:
center (垂直且水平居中)
center_horizontal (水平居中)
bottom (底部對(duì)齊)
center_vertical (垂直居中)
clip_horizontal (水平方向裁剪,當(dāng)對(duì)象邊緣超出容器的時(shí)候,將上下邊緣超出的部分剪切掉,剪切基于縱向?qū)R設(shè)置:頂部對(duì)齊時(shí),剪切底部;底部對(duì)齊時(shí)剪切頂部;除此之外剪切頂部和底部.)
clip_vertical (垂直方向裁剪,當(dāng)對(duì)象邊緣超出容器的時(shí)候,將左右邊緣超出的部分剪切掉,剪切基于橫向?qū)R設(shè)置:左對(duì)齊時(shí),剪切右邊部分;右對(duì)齊時(shí)剪切左邊部分;除此之外剪切左邊和右邊部分.)
end (放在容器的結(jié)束位置,不改變其大小)
fill (必要的時(shí)候增加對(duì)象的橫縱向大小,以完全充滿(mǎn)其容器)
fill_horizontal (必要的時(shí)候增加對(duì)象的橫向大小,以完全充滿(mǎn)其容器. 水平方向充)
fill_vertical (必要的時(shí)候增加對(duì)象的縱向大小,以完全充滿(mǎn)其容器. 垂直方向填充)
left (將對(duì)象放在其容器的左部,不改變其大小)
right (將對(duì)象放在其容器的右部,不改變其大小)
start (將對(duì)象放在其容器的開(kāi)始位置,不改變其大小)
top (將對(duì)象放在其容器的頂部,不改變其大小)

android:layout_gravity: 表示當(dāng)前線性布局相對(duì)于父元素的對(duì)齊方式
如上所示
android:background: 表示當(dāng)前線性布局的背景顏色
android:margin:表示外邊距,通常表示本控件與父控件四面之間的距離

這里寫(xiě)圖片描述 

從上往下:
1. 底邊距
2. 與控件結(jié)尾的邊距
3. 左邊距
4. 右邊距
5. 與控件的起始邊距
6. 頂邊距

android:padding:表示內(nèi)邊距,通常表示是本元素所有子元素的與父元素邊緣的距離,設(shè)置在父元素上,比如文字與文本控件的所有距離

這里寫(xiě)圖片描述 

從上往下如上所示
android:weightSum:權(quán)重的總比例
android:layout_weight:子元素對(duì)未占用空間水平或垂直分布的權(quán)重

<?xml version="1.0" encoding="utf-8"?>
<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"
 tools:context="com.qianfeng.demo1.MainActivity"
 android:weightSum="6" //總的權(quán)重為6
 android:orientation="vertical"
 >
 <TextView
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:layout_weight="2"http://此控件占用比例為2,其他控件全部占用1,超過(guò)比例的權(quán)重都不會(huì)分配對(duì)應(yīng)的大小,相當(dāng)于大小為0
 android:textSize="30sp"
 android:text="aaaa"
 android:background="#f00"
 p
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:layout_weight="1"
 android:textSize="30sp"
 android:text="bbbb"
 android:background="#0f0"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:layout_weight="1"
 android:textSize="30sp"
 android:background="#00f"
 android:text="cccc"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:layout_weight="1"
 android:textSize="30sp"
 android:text="dddd"
 android:background="#0ff"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:layout_weight="1"
 android:textSize="30sp"
 android:background="#f0f"
 android:text="eeee"

 />
</LinearLayout>

效果圖如下:

這里寫(xiě)圖片描述

android:baselineAligned:該控件只對(duì)能顯示text的子控件有效。
這必須是一個(gè)布爾值,要么“true”或“false”,并防止布局調(diào)整其子的基線。默認(rèn)是true

這里介紹一個(gè)小細(xì)節(jié):

這里以垂直分配權(quán)重為列,權(quán)重是可以為負(fù)數(shù)的,權(quán)重是根據(jù)比例分配對(duì)應(yīng)大小,這里aaaa控件的高為0dp,bbbb控件的高為0dp,所以,aaaa控件分配權(quán)重的是5,bbbb分配權(quán)重的是1,所以這里aaaa會(huì)比bbbb占用比例大。

<?xml version="1.0" encoding="utf-8"?>
<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"
 tools:context="com.qianfeng.demo1.MainActivity"
 android:weightSum="6"
 android:orientation="vertical"
 >
 <TextView
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:layout_weight="5"
 android:textSize="30sp"
 android:text="aaaa"
 android:background="#f00"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="0dp"
 android:layout_weight="1"
 android:textSize="30sp"
 android:text="bbbb"
 android:background="#0f0"
 />

</LinearLayout>


效果圖:

這里寫(xiě)圖片描述

反之,如果設(shè)置了aaaa控件的高為match_parent, bbbb控件的高也為match_parent,aaaa控件分配權(quán)重的是5,bbbb分配權(quán)重的是1,這樣就形成了一種想反的效果,相當(dāng)于aaaa控件分配的是-5 bbbb控件分配的是-1 而-1 比 -5大,所以,對(duì)應(yīng)bbbb控件占用的比例比aaaa大

<?xml version="1.0" encoding="utf-8"?>
<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"
 tools:context="com.qianfeng.demo1.MainActivity"
 android:weightSum="6"
 android:orientation="vertical"
 >
 <TextView
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_weight="5"
 android:textSize="30sp"
 android:text="aaaa"
 android:background="#f00"
 />
 <TextView
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_weight="1"
 android:textSize="30sp"
 android:text="bbbb"
 android:background="#0f0"
 />

</LinearLayout>

效果圖如下:

這里寫(xiě)圖片描述

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論