一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Android中的LinearLayout布局

Android中的LinearLayout布局

2020-07-24 12:16bigboss位 Java教程

在一般情況下,當有很多控件需要在一個界面列出來時,我們就可以使用線性布局(LinearLayout)了,線性布局是按照垂直方向(vertical)或水平方向(horizontal)的順序依次排序子元素,每一個子元素都位于前一個元素之后,下面我們就簡單的了解一

LinearLayout : 線性布局

在一般情況下,當有很多控件需要在一個界面列出來時,我們就可以使用線性布局(LinearLayout)了,  線性布局是按照垂直方向(vertical)或水平方向(horizontal)的順序依次排序子元素,每一個子元素都位于前一個元素之后,下面我們就簡單的了解一下吧

在XML布局文件中會遇到如下一些單位

px:是屏幕的像素點   dp:一個基于density的抽象單位,屏幕的物理尺寸   sp:同dp相似,但會根據用戶的字體大小進行縮放 

XML代碼如下:改變一下android:orientation="vertical"  垂直方向(vertical)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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>

運行結果:每一個TextView都從上往下依次排列

Android中的LinearLayout布局

XML代碼如下:改變一下android:orientation="horizontal"  水平方向(horizontal)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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>

運行結果:每一個TextView都從左向右依次水平排列

Android中的LinearLayout布局

這兩種線性布局唯一的差別就是android:orientation的值不同

實驗總結:這兩種線性布局唯一的差別就是android:orientation的值不同, 通過本次實驗對Android中的線性布局有了一個初步的了解

 以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持服務器之家!

原文鏈接:http://www.cnblogs.com/bigbossOne/p/6259937.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久xxxx| 欧美人妖大啪啪 | 国色天香高清版 | 99久久伊人一区二区yy5099 | 免费看欧美一级特黄a大片一 | 美女扒开腿让男生桶爽漫画 | 色网在线视频 | 久久精品在现线观看免费15 | 欧美猛男同志同性video | jk制服喷水 | 国产裸舞福利资源在线视频 | 丝瓜视频黄瓜视频 | 嫩草影院永久在线一二三四 | 美女奶口隐私免费视频网站 | 色综合久久九月婷婷色综合 | 国产婷婷成人久久av免费高清 | 国产伦精品一区二区三区免费观看 | 办公室操秘书 | 美女扒开腿让男人桶爽免费gif | 人与蛇boxxⅹ | 激情五月姐姐 | 日本漫画被黄漫免费动 | 亚洲另类老妇videos | 日韩一区二区三区精品 | 亚洲小视频在线 | 欧美巨吊 | 香蕉久久夜色精品国产尤物 | 999资源站 | 亚洲免费国产 | 天堂va在线 | zozzozozozo大| 国产色司机在线视频免费观看 | 亚欧日韩 | 黑帮少爷爱上我第8集在线观看 | 亚洲国产成人久久综合区 | 国产精品麻豆久久99 | 四虎最新永久免费网址 | 天天做天天玩天天爽天天 | 国产精品igao视频网网址 | 国产福利在线观看91精品 | 欧美日韩亚洲综合久久久 |