Android中的LinearLayout布局
LinearLayout : 線性布局
在一般情況下,當(dāng)有很多控件需要在一個(gè)界面列出來(lái)時(shí),我們就可以使用線性布局(LinearLayout)了, 線性布局是按照垂直方向(vertical)或水平方向(horizontal)的順序依次排序子元素,每一個(gè)子元素都位于前一個(gè)元素之后,下面我們就簡(jiǎn)單的了解一下吧
在XML布局文件中會(huì)遇到如下一些單位
px:是屏幕的像素點(diǎn) dp:一個(gè)基于density的抽象單位,屏幕的物理尺寸 sp:同dp相似,但會(huì)根據(jù)用戶的字體大小進(jìn)行縮放
XML代碼如下:改變一下android:orientation="vertical" 垂直方向(vertical)
<?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" android:orientation="vertical" tools:context="com.example.administrator.adapter.MainActivity"> <TextView android:text="第一個(gè)TextView" android:background="#ef0808" android:gravity="center" android:textSize="18sp" android:layout_width="match_parent" android:layout_height="100dp" /> <TextView android:text="第二個(gè)TextView" android:gravity="center" android:background="#31ef0b" android:textSize="18sp" android:layout_width="match_parent" android:layout_height="100dp" /> <TextView android:text="第三個(gè)TextView" android:gravity="center" android:textSize="18sp" android:background="#ec07ca" android:layout_width="match_parent" android:layout_height="100dp" /> <TextView android:text="第四個(gè)TextView" android:gravity="center" android:textSize="18sp" android:background="#f5d105" android:layout_width="match_parent" android:layout_height="100dp" /> </LinearLayout>
運(yùn)行結(jié)果:每一個(gè)TextView都從上往下依次排列

XML代碼如下:改變一下android:orientation="horizontal" 水平方向(horizontal)
<?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" android:orientation="horizontal" tools:context="com.example.administrator.adapter.MainActivity"> <TextView android:text="第一個(gè)TextView" android:background="#ef0808" android:gravity="center" android:textSize="18sp" android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:text="第二個(gè)TextView" android:gravity="center" android:background="#31ef0b" android:textSize="18sp" android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:text="第三個(gè)TextView" android:gravity="center" android:textSize="18sp" android:background="#ec07ca" android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:text="第四個(gè)TextView" android:gravity="center" android:textSize="18sp" android:background="#f5d105" android:layout_width="100dp" android:layout_height="100dp" /> </LinearLayout>
運(yùn)行結(jié)果:每一個(gè)TextView都從左向右依次水平排列

這兩種線性布局唯一的差別就是android:orientation的值不同
實(shí)驗(yàn)總結(jié):這兩種線性布局唯一的差別就是android:orientation的值不同, 通過本次實(shí)驗(yàn)對(duì)Android中的線性布局有了一個(gè)初步的了解
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
- Android LinearLayout實(shí)現(xiàn)自動(dòng)換行效果
- Android LinearLayout實(shí)現(xiàn)自動(dòng)換行
- Android自定義LinearLayout布局顯示不完整的解決方法
- Android使用LinearLayout設(shè)置邊框
- Android編程使用LinearLayout和PullRefreshView實(shí)現(xiàn)上下翻頁(yè)功能的方法
- android中LinearLayoutManager一鍵返回頂部示例
- Android基礎(chǔ)之獲取LinearLayout的寬高
- Android超詳細(xì)講解組件LinearLayout的使用
相關(guān)文章
淺析Java如何在并發(fā)環(huán)境下生成一個(gè)只讀的map
這篇文章主要為大家詳細(xì)介紹了Java如何在并發(fā)環(huán)境下生成一個(gè)只讀的map,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-04-04
SpringBoot實(shí)現(xiàn)文件上傳下載功能小結(jié)
最近做的一個(gè)項(xiàng)目涉及到文件上傳與下載功能。SpringBoot后臺(tái)如何實(shí)現(xiàn)文件上傳下載呢?下面有單文件上傳和多文件上傳功能,感興趣的朋友一起看看吧2017-08-08
新手初學(xué)Java對(duì)象內(nèi)存構(gòu)成
這篇文章主要介紹了深入理解JVM之Java對(duì)象的創(chuàng)建、內(nèi)存布局、訪問定位,結(jié)合實(shí)例形式詳細(xì)分析了Java對(duì)象的創(chuàng)建、內(nèi)存布局、訪問定位相關(guān)概念、原理、操作技巧與注意事項(xiàng),需要的朋友可以參考下2021-07-07
IDEA2023常用配置指南(JDK/系統(tǒng)設(shè)置等常用配置)
idea很強(qiáng)大,但是初次安裝默認(rèn)的有很多設(shè)置并不是滿足我們開發(fā)的需要,下面這篇文章主要給大家介紹了關(guān)于IDEA2023常用配置(JDK/系統(tǒng)設(shè)置等常用配置)的相關(guān)資料,需要的朋友可以參考下2023-12-12
Spring MVC 接口 ResponseBodyAdvice 及其應(yīng)用最佳實(shí)
ResponseBodyAdvice?是 Spring MVC 提供的一個(gè)強(qiáng)大接口,允許你在響應(yīng)體被寫入 HTTP 響應(yīng)之前對(duì)其進(jìn)行全局處理,下面我將全面介紹它的工作原理、使用場(chǎng)景和最佳實(shí)踐,感興趣的朋友一起看看吧2025-04-04
RocketMQ之NameServer架構(gòu)設(shè)計(jì)及啟動(dòng)關(guān)閉流程源碼分析
這篇文章主要為大家介紹了RocketMQ之NameServer架構(gòu)設(shè)計(jì)及啟動(dòng)關(guān)閉流程源碼分析詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2021-11-11

