Android中的LinearLayout布局
LinearLayout : 線性布局
在一般情況下,當有很多控件需要在一個界面列出來時,我們就可以使用線性布局(LinearLayout)了, 線性布局是按照垂直方向(vertical)或水平方向(horizontal)的順序依次排序子元素,每一個子元素都位于前一個元素之后,下面我們就簡單的了解一下吧
在XML布局文件中會遇到如下一些單位
px:是屏幕的像素點 dp:一個基于density的抽象單位,屏幕的物理尺寸 sp:同dp相似,但會根據(jù)用戶的字體大小進行縮放
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="第一個TextView" android:background="#ef0808" android:gravity="center" android:textSize="18sp" android:layout_width="match_parent" android:layout_height="100dp" /> <TextView android:text="第二個TextView" android:gravity="center" android:background="#31ef0b" android:textSize="18sp" android:layout_width="match_parent" android:layout_height="100dp" /> <TextView android:text="第三個TextView" android:gravity="center" android:textSize="18sp" android:background="#ec07ca" android:layout_width="match_parent" android:layout_height="100dp" /> <TextView android:text="第四個TextView" android:gravity="center" android:textSize="18sp" android:background="#f5d105" android:layout_width="match_parent" android:layout_height="100dp" /> </LinearLayout>
運行結(jié)果:每一個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="第一個TextView" android:background="#ef0808" android:gravity="center" android:textSize="18sp" android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:text="第二個TextView" android:gravity="center" android:background="#31ef0b" android:textSize="18sp" android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:text="第三個TextView" android:gravity="center" android:textSize="18sp" android:background="#ec07ca" android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:text="第四個TextView" android:gravity="center" android:textSize="18sp" android:background="#f5d105" android:layout_width="100dp" android:layout_height="100dp" /> </LinearLayout>
運行結(jié)果:每一個TextView都從左向右依次水平排列
這兩種線性布局唯一的差別就是android:orientation的值不同
實驗總結(jié):這兩種線性布局唯一的差別就是android:orientation的值不同, 通過本次實驗對Android中的線性布局有了一個初步的了解
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
springboot下實現(xiàn)RedisTemplate?List?清空
我們經(jīng)常會使用Redis的List數(shù)據(jù)結(jié)構(gòu)來存儲一系列的元素,當我們需要清空一個List時,可以使用RedisTemplate來實現(xiàn),本文就來詳細的介紹一下如何實現(xiàn),感興趣的可以了解一下2024-01-01使用jackson實現(xiàn)對象json之間的相互轉(zhuǎn)換(spring boot)
這篇文章主要介紹了使用jackson實現(xiàn)對象json之間的相互轉(zhuǎn)換(spring boot),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09javaweb判斷當前請求是否為移動設(shè)備訪問的方法
這篇文章主要為大家詳細介紹了javaweb判斷當前請求是否為移動設(shè)備訪問的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05Spring AOP里的靜態(tài)代理和動態(tài)代理用法詳解
這篇文章主要介紹了 Spring AOP里的靜態(tài)代理和動態(tài)代理用法詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07SpringMVC轉(zhuǎn)發(fā)與重定向參數(shù)傳遞的實現(xiàn)詳解
這篇文章主要介紹了SpringMVC轉(zhuǎn)發(fā)與重定向參數(shù)傳遞,對于重定向,可以通過FlashMap或RedirectAttributes來在請求間傳遞數(shù)據(jù),因為重定向涉及兩個獨立的HTTP請求,而轉(zhuǎn)發(fā)則在同一請求內(nèi)進行,數(shù)據(jù)可以直接通過HttpServletRequest共享,需要的朋友可以參考下2022-07-07