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的值不同, 通過(guò)本次實(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)文章
springboot下實(shí)現(xiàn)RedisTemplate?List?清空
我們經(jīng)常會(huì)使用Redis的List數(shù)據(jù)結(jié)構(gòu)來(lái)存儲(chǔ)一系列的元素,當(dāng)我們需要清空一個(gè)List時(shí),可以使用RedisTemplate來(lái)實(shí)現(xiàn),本文就來(lái)詳細(xì)的介紹一下如何實(shí)現(xiàn),感興趣的可以了解一下2024-01-01使用jackson實(shí)現(xiàn)對(duì)象json之間的相互轉(zhuǎn)換(spring boot)
這篇文章主要介紹了使用jackson實(shí)現(xiàn)對(duì)象json之間的相互轉(zhuǎn)換(spring boot),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09Javacv使用ffmpeg實(shí)現(xiàn)音視頻同步播放
這篇文章主要介紹了Javacv使用ffmpeg實(shí)現(xiàn)音視頻同步播放,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12javaweb判斷當(dāng)前請(qǐng)求是否為移動(dòng)設(shè)備訪問(wèn)的方法
這篇文章主要為大家詳細(xì)介紹了javaweb判斷當(dāng)前請(qǐng)求是否為移動(dòng)設(shè)備訪問(wèn)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Spring AOP里的靜態(tài)代理和動(dòng)態(tài)代理用法詳解
這篇文章主要介紹了 Spring AOP里的靜態(tài)代理和動(dòng)態(tài)代理用法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07Java實(shí)現(xiàn)的簡(jiǎn)單網(wǎng)頁(yè)截屏功能示例
這篇文章主要介紹了Java實(shí)現(xiàn)的簡(jiǎn)單網(wǎng)頁(yè)截屏功能,涉及java網(wǎng)頁(yè)打開(kāi)及屏幕截圖功能相關(guān)操作技巧,需要的朋友可以參考下2017-12-12通過(guò)RedisTemplate連接多個(gè)Redis過(guò)程解析
這篇文章主要介紹了通過(guò)RedisTemplate連接多個(gè)Redis過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08SpringMVC轉(zhuǎn)發(fā)與重定向參數(shù)傳遞的實(shí)現(xiàn)詳解
這篇文章主要介紹了SpringMVC轉(zhuǎn)發(fā)與重定向參數(shù)傳遞,對(duì)于重定向,可以通過(guò)FlashMap或RedirectAttributes來(lái)在請(qǐng)求間傳遞數(shù)據(jù),因?yàn)橹囟ㄏ蛏婕皟蓚€(gè)獨(dú)立的HTTP請(qǐng)求,而轉(zhuǎn)發(fā)則在同一請(qǐng)求內(nèi)進(jìn)行,數(shù)據(jù)可以直接通過(guò)HttpServletRequest共享,需要的朋友可以參考下2022-07-07