Android編程之線性布局LinearLayout實(shí)例簡析
本文實(shí)例講述了Android編程之線性布局LinearLayout用法。分享給大家供大家參考,具體如下:
線性布局(LinearLayout)
可以讓它的子元素垂直或水平的方式排成一行(不設(shè)置方向的時(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:控制各個(gè)組件在布局中的相對大小
更多關(guān)于Android編程布局相關(guān)內(nèi)容可查看本站專題:《Android布局layout技巧總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- Android應(yīng)用的LinearLayout中嵌套RelativeLayout的布局用法
- Android App中的多個(gè)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解析服務(wù)器端發(fā)來的xml數(shù)據(jù)示例
Android跟服務(wù)器交互數(shù)據(jù),有時(shí)數(shù)據(jù)量大時(shí),就需要以xml形式的交互數(shù)據(jù),下面與大家分享下使用XmlPullParser來解析xml數(shù)據(jù),感興趣的朋友可以參考下哈2013-06-06
Android 中使用 dlib+opencv 實(shí)現(xiàn)動態(tài)人臉檢測功能
完成 Android 相機(jī)預(yù)覽功能以后,在此基礎(chǔ)上我使用 dlib 與 opencv 庫做了一個(gè)關(guān)于人臉檢測的 demo。接下來通過本文給大家介紹Android 中使用 dlib+opencv 實(shí)現(xiàn)動態(tài)人臉檢測功能 ,需要的朋友可以參考下2018-11-11
Android屬性動畫實(shí)現(xiàn)炫酷的登錄界面
這篇文章主要為大家詳細(xì)介紹了Android屬性動畫實(shí)現(xiàn)炫酷的登錄界面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07
Android 使用Fragment模仿微信界面的實(shí)例代碼
自從Android 3.0中引入fragments 的概念,根據(jù)詞海的翻譯可以譯為:碎片、片段。其目的是為了解決不同屏幕分辯率的動態(tài)和靈活UI設(shè)計(jì)。下面通過本文給大家分享Android 使用Fragment模仿微信界面的實(shí)例代碼,需要的的朋友參考下吧2017-07-07
Android 監(jiān)聽?wèi)?yīng)用前/后臺切換實(shí)例代碼
本篇文章主要介紹了Android 監(jiān)聽?wèi)?yīng)用前/后臺切換實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06
Android實(shí)現(xiàn)自定義dialog的代碼
這篇文章主要介紹了Android實(shí)現(xiàn)自定義dialog的實(shí)例代碼,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-11-11
Android Studio使用ButterKnife和Zelezny的方法
這篇文章主要為大家詳細(xì)介紹了Android Studio使用ButterKnife和Zelezny的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04

