Android編程之線性布局LinearLayout實(shí)例簡析
本文實(shí)例講述了Android編程之線性布局LinearLayout用法。分享給大家供大家參考,具體如下:
線性布局(LinearLayout)
可以讓它的子元素垂直或水平的方式排成一行(不設(shè)置方向的時候默認(rèn)按照垂直方向排列)。
下面示例是在別人基礎(chǔ)上修改的main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:baselineAligned="false" android:layout_weight="1" > <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"> <TextView android:text="@string/color_green" android:textColor="#ff0000" android:background="#00aa00" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/> <TextView android:text="@string/color_blue" android:background="#0000aa" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"> <TextView android:text="@string/color_black" android:background="#000000" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <TextView android:text="@string/color_yellow" android:background="#aaaa00" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <TextView android:text="@string/color_unknown" android:background="#00aaaa" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> </LinearLayout> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2"> <TextView android:text="@string/color_red" android:gravity="fill_vertical" android:background="#aa0000" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2"/> <TextView android:text="@string/color_white" android:textColor="#ff0000" android:background="#ffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2"/> </LinearLayout> </LinearLayout>
string.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, TestAbsoluteLayoutActivity!</string> <string name="app_name">TestAbsoluteLayout</string> <string name= "color_red">red</string> <string name= "color_green">green</string> <string name= "color_blue">blue</string> <string name= "color_white">white</string> <string name= "color_black">black</string> <string name= "color_yellow">yellow</string> <string name= "color_unknown">unknown</string> </resources>
效果圖如下:
常用的屬性:
android:orientation:可以設(shè)置布局的方向
android:gravity:用來控制組件的對齊方式
layout_weight:控制各個組件在布局中的相對大小
更多關(guān)于Android編程布局相關(guān)內(nèi)容可查看本站專題:《Android布局layout技巧總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- Android應(yīng)用的LinearLayout中嵌套RelativeLayout的布局用法
- Android App中的多個LinearLayout嵌套布局實(shí)例解析
- Android App中使用LinearLayout進(jìn)行居中布局的實(shí)例講解
- Android應(yīng)用借助LinearLayout實(shí)現(xiàn)垂直水平居中布局
- Android布局之LinearLayout自定義高亮背景的方法
- Android布局控件之常用linearlayout布局
- Android布局之LinearLayout線性布局
- Android入門之LinearLayout、AbsoluteLayout的用法實(shí)例講解
- android 線性布局LinearLayout實(shí)例代碼
- Android 布局控件之LinearLayout詳細(xì)介紹
- android LinearLayout 布局實(shí)例代碼
- android LinearLayout和RelativeLayout組合實(shí)現(xiàn)精確布局方法介紹
- Android中LinearLayout布局的常用屬性總結(jié)
相關(guān)文章
Android App中的GridView網(wǎng)格布局使用指南
GridView布局所實(shí)現(xiàn)的就是類似于九宮格的矩陣界面效果,下面整理了Android App中的GridView網(wǎng)格布局使用指南,包括分割線的添加與自定義GridView的實(shí)現(xiàn)等技巧,需要的朋友可以參考下2016-06-06Android自定義listview布局實(shí)現(xiàn)上拉加載下拉刷新功能
這篇文章主要介紹了Android自定義listview布局實(shí)現(xiàn)上拉加載下拉刷新功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-12-12Android控件RadioButton實(shí)現(xiàn)多選一功能
這篇文章主要為大家詳細(xì)介紹了Android控件RadioButton實(shí)現(xiàn)多選一功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08Android Material加載進(jìn)度條制作代碼
這篇文章主要為大家詳細(xì)介紹了AndroidMaterial加載進(jìn)度條的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01Android 將view 轉(zhuǎn)換為Bitmap出現(xiàn)空指針問題解決辦法
這篇文章主要介紹了Android 將view 轉(zhuǎn)換為Bitmap出現(xiàn)空指針問題解決辦法的相關(guān)資料,這里提供實(shí)例并提供解決辦法,需要的朋友可以參考下2017-07-07Android-實(shí)現(xiàn)切換Fragment頁功能的實(shí)現(xiàn)代碼
本篇文章主要介紹了Android-實(shí)現(xiàn)切換Fragment頁功能的實(shí)現(xiàn)代碼,具有一定的參加價值,有興趣的可以了解一下。2017-02-02android開發(fā)實(shí)現(xiàn)列表控件滾動位置精確保存和恢復(fù)的方法(推薦)
下面小編就為大家?guī)硪黄猘ndroid開發(fā)實(shí)現(xiàn)列表控件滾動位置精確保存和恢復(fù)的方法(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03