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

Android 五大布局方式詳解

 更新時間:2016年09月05日 10:56:52   作者:lingdududu  
本文主要介紹Android 五大布局的知識資料,這里整理了詳細的布局資料及實現(xiàn)示例代碼,和實現(xiàn)效果圖,有興趣的小伙伴可以參考下

Android中常用的5大布局方式有以下幾種:

線性布局(LinearLayout):按照垂直或者水平方向布局的組件。
幀布局(FrameLayout):組件從屏幕左上方布局組件。
表格布局(TableLayout):按照行列方式布局組件。
相對布局(RelativeLayout):相對其它組件的布局方式。
 絕對布局(AbsoluteLayout):按照絕對坐標(biāo)來布局組件。

 1. 線性布局

線性布局是Android開發(fā)中最常見的一種布局方式,它是按照垂直或者水平方向來布局,通過“android:orientation”屬性可以設(shè)置線性布局的方向。屬性值有垂直(vertical)和水平(horizontal)兩種。

常用的屬性:

android:orientation:可以設(shè)置布局的方向
android:gravity:用來控制組件的對齊方式
layout_weight:控制各個組件在布局中的相對大小

第一個實例

①效果圖:

 ②核心代碼如下:

main.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 > 
 <LinearLayout 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:orientation="vertical" 
 > 
 <EditText 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  /> 
 </LinearLayout> 
 <LinearLayout 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:orientation="horizontal" 
 android:gravity="right" 
 > 
 <!-- android:gravity="right"表示Button組件向右對齊 --> 
 <Button 
  android:layout_height="wrap_content" 
  android:layout_width="wrap_content" 
  android:text="確定" 
  /> 
 <Button 
  android:layout_height="wrap_content" 
  android:layout_width="wrap_content" 
  android:text="取消" 
  /> 
 </LinearLayout> 
</LinearLayout> 

第二個實例

①效果圖:

 ②核心代碼:

mian.xml
 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical" android:layout_width="fill_parent" 
 android:layout_height="fill_parent"> 
 
 <LinearLayout 
 android:orientation="horizontal" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:layout_weight="1"> 
 
 <TextView 
 android:text="red" 
 android:gravity="center_horizontal" 
 android:background="#aa0000" 
 android:layout_width="wrap_content" 
 android:layout_height="fill_parent" 
 android:layout_weight="1" 
 /> 
 <!--android:gravity="center_horizontal"水平居中 --> 
 <!--layout_weight屬性以控制各個控件在布局中的相對大小。layout_weight屬性是一個非負整數(shù)值。 
  線性布局會根據(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)的比例來分配每一個控件顯示的寬度或高度--> 
 <TextView 
 android:text="Teal" 
 android:gravity="center_horizontal" 
 android:background="#008080" 
 android:layout_width="wrap_content" 
 android:layout_height="fill_parent" 
 android:layout_weight="1"/> 
 
 <TextView 
 android:text="blue" 
 android:gravity="center_horizontal" 
 android:background="#0000aa" 
 android:layout_width="wrap_content" 
 android:layout_height="fill_parent" 
 android:layout_weight="1" 
 /> 
 
 <TextView 
 android:text="orange" 
 android:gravity="center_horizontal" 
 android:background="#FFA500" 
 android:layout_width="wrap_content" 
 android:layout_height="fill_parent" 
 android:layout_weight="1" 
 /> 
  
 </LinearLayout> 
 <LinearLayout 
 android:orientation="vertical" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:layout_weight="1"> 
 
 <TextView 
 android:text="row one" 
 android:textSize="15pt" 
 android:background="#aa0000" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:layout_weight="1" 
 /> 
 <!-- --> 
 <TextView 
 android:text="row two" 
 android:textSize="15pt" 
 android:background="#DDA0DD" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:layout_weight="1" 
 /> 
 
 <TextView 
 android:text="row three" 
 android:textSize="15pt" 
 android:background="#008080" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:layout_weight="1" 
 /> 
 <TextView 
 android:text="row four" 
 android:textSize="15pt" 
 android:background="#FFA500" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:layout_weight="1" 
 /> 
 </LinearLayout> 
</LinearLayout> 

2. 幀布局

幀布局是從屏幕的左上角(0,0)坐標(biāo)開始布局,多個組件層疊排列,第一個添加的組件放到最底層,最后添加到框架中的視圖顯示在最上面。上一層的會覆蓋下一層的控件。

 簡單的例子

①效果圖:

 

② 核心代碼:

main.xml
<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 > 
 <TextView 
 android:layout_width="300dp" 
 android:layout_height="300dp" 
 android:background="#00BFFF"  
 /> 
 <TextView 
 android:layout_width="260dp" 
 android:layout_height="260dp" 
 android:background="#FFC0CB"  
 /> 
 <TextView 
 android:layout_width="220dp" 
 android:layout_height="220dp" 
 android:background="#0000FF"  
 /> 
</FrameLayout> 

 3.表格布局

表格布局是一個ViewGroup以表格顯示它的子視圖(view)元素,即行和列標(biāo)識一個視圖的位置。

表格布局常用的屬性如下:

android:collapseColumns:隱藏指定的列
android:shrinkColumns:收縮指定的列以適合屏幕,不會擠出屏幕
android:stretchColumns:盡量把指定的列填充空白部分
android:layout_column:控件放在指定的列
android:layout_span:該控件所跨越的列數(shù)

 簡單的列子:

①效果圖:

② 核心代碼: 

main.xml
 
<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 > 
 <TableRow> 
 <Button 
  android:text="Button1" 
  /> 
 <Button 
  android:text="Button2" 
  /> 
 <Button 
  android:text="Button3" 
  /> 
 </TableRow> 
 <TableRow> 
 <Button 
  android:text="Button4" 
  /> 
 <Button 
  android:layout_span="2" 
  android:text="Button5" 
  /> 
 </TableRow> 
 
</TableLayout> 

 4.相對布局

相對布局是按照組件之間的相對位置來布局,比如在某個組件的左邊,右邊,上面和下面等。

相對布局常用屬性請參考我博客的:http://www.fzitv.net/article/47434.htm

簡單的例子

①效果圖:

② 核心代碼:

main.xml
 
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:padding="10px" 
 > 
 <TextView 
 android:id="@+id/tev1" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_marginBottom="30dp" 
 android:text="Please Type Here:" 
 /> 
 <EditText 
 android:id="@+id/tx1" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_below="@id/tev1" 
 /> 
 <Button 
 android:id="@+id/btn1" 
 android:layout_height="wrap_content" 
 android:layout_width="wrap_content" 
 android:layout_below="@id/tx1" 
 android:layout_alignParentRight="true" 
 android:text="確定" 
 /> 
 <Button 
 android:id="@+id/btn2" 
 android:layout_height="wrap_content" 
 android:layout_width="wrap_content" 
 android:layout_below="@id/tx1" 
 android:layout_toLeftOf="@id/btn1" 
 android:layout_marginRight="30dp" 
 android:text="取消" 
 /> 
</RelativeLayout> 

5. 絕對布局

絕對布局通過指定子組件的確切X,Y坐標(biāo)來確定組件的位置,在Android2.0 API文檔中標(biāo)明該類已經(jīng)過期,可以使用FrameLayout或者RelativeLayout來代替。所以這里不再詳細介紹。

以上就是對 Android 五大布局的資料整理,后續(xù)繼續(xù)補充相關(guān)資料,謝謝大家對本站的支持!

相關(guān)文章

  • RxJava兩步打造華麗的Android引導(dǎo)頁

    RxJava兩步打造華麗的Android引導(dǎo)頁

    如今,移動應(yīng)用對首次使用的用戶呈現(xiàn)歡迎頁已經(jīng)越來越普遍了。這樣做的目的就是向用戶介紹并展示我們的應(yīng)用。本文給Android開發(fā)的引導(dǎo)頁面提供了很多參考,非常值得一讀。
    2016-07-07
  • Android解析json數(shù)組對象的方法及Apply和數(shù)組的三個技巧

    Android解析json數(shù)組對象的方法及Apply和數(shù)組的三個技巧

    這篇文章主要介紹了Android解析json數(shù)組對象的方法及Apply和數(shù)組的三個技巧的相關(guān)資料,需要的朋友可以參考下
    2015-12-12
  • Android子線程與更新UI問題的深入講解

    Android子線程與更新UI問題的深入講解

    首先和其他許多的GUI庫一樣,Android的UI線程是不安全的。所以下面這篇文章主要給大家介紹了關(guān)于Android子線程與更新UI問題的相關(guān)資料,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • Android?JobScheduler詳細介紹

    Android?JobScheduler詳細介紹

    JobScheduler是Android?5.0引入的系統(tǒng)服務(wù),它可以根據(jù)網(wǎng)絡(luò)狀態(tài)、充電狀態(tài)、電量和存儲狀況等來觸發(fā)相應(yīng)的JobService執(zhí)行任務(wù),它支持多條件組合、持久性任務(wù),以及在API?21以上版本的Android系統(tǒng)中使用,對Android?JobScheduler相關(guān)知識感興趣的朋友跟隨小編一起看看吧
    2024-09-09
  • 詳解android 中文字體向上偏移解決方案

    詳解android 中文字體向上偏移解決方案

    這篇文章主要介紹了詳解android 中文字體向上偏移解決方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • Android Doze模式啟用和恢復(fù)詳解

    Android Doze模式啟用和恢復(fù)詳解

    這篇文章主要介紹了Android Doze模式啟用和恢復(fù)功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-03-03
  • Android 實現(xiàn)圓角圖片的簡單實例

    Android 實現(xiàn)圓角圖片的簡單實例

    這篇文章主要介紹了Android 實現(xiàn)圓角圖片的簡單實例的相關(guān)資料,Android 圓角圖片的實現(xiàn)形式,包括用第三方、也有系統(tǒng),需要的朋友可以參考下
    2017-07-07
  • Flutter開發(fā)技巧RadialGradient中radius計算詳解

    Flutter開發(fā)技巧RadialGradient中radius計算詳解

    這篇文章主要為大家介紹了Flutter小技巧RadialGradient?中?radius?的計算詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • Android實現(xiàn)沉浸式導(dǎo)航欄實例代碼

    Android實現(xiàn)沉浸式導(dǎo)航欄實例代碼

    通過本文給大家分享android實現(xiàn)沉浸式導(dǎo)航欄實例代碼,代碼非常實用,需要的朋友可以參考下
    2016-05-05
  • Android TV開發(fā):使用RecycleView實現(xiàn)橫向的Listview并響應(yīng)點擊事件的代碼

    Android TV開發(fā):使用RecycleView實現(xiàn)橫向的Listview并響應(yīng)點擊事件的代碼

    這篇文章主要介紹了Android TV開發(fā):使用RecycleView實現(xiàn)橫向的Listview并響應(yīng)點擊事件的代碼,具有很好的參考價值,希望對大家有所幫助,一起跟隨小編過來看看吧
    2018-05-05

最新評論

天气| 孝昌县| 定安县| 五莲县| 平谷区| 高阳县| 桑日县| 响水县| 全州县| 长海县| 宁安市| 滨州市| 苗栗市| 凤凰县| 新营市| 崇信县| 右玉县| 门头沟区| 宁波市| 凌海市| 昌邑市| 来安县| 阿勒泰市| 炎陵县| 兴安县| 惠州市| 宜春市| 定兴县| 红桥区| 凯里市| 铁力市| 临夏县| 易门县| 青岛市| 临夏市| 呼图壁县| 新源县| 西乌| 巴东县| 安吉县| 兰州市|