最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Android開(kāi)發(fā)學(xué)習(xí)教程(12)- Android布局之線性布局LinearLayout

2023-01-27 16:04 作者:考研保研直通車  | 我要投稿


—— 當(dāng)下的生活或許疲憊又難熬,但你要相信,始終沒(méi)有放棄過(guò)的你,一定會(huì)過(guò)上想要的生活。

上一篇我們講了對(duì)話框AlertDialog的基本用法,這里來(lái)學(xué)習(xí)常用布局之線性布局的基本用法。

線性布局是什么

線性布局中的控件按照橫向或豎向排列,并且線性布局不會(huì)換行,當(dāng)控件超出屏幕邊緣,后面的控件就被隱藏,不會(huì)被顯示出來(lái)。

線性布局有什么用

控制其中的控件只能橫向或豎向排列。

線性布局怎么用

繼續(xù)基于上一篇的項(xiàng)目,我們新建一個(gè)LinearLayoutActivity:

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
<?xml?version="1.0"?encoding="utf-8"?>
<LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:layout_width="match_parent"
????android:layout_height="match_parent"
????android:gravity="center"
????android:orientation="horizontal">
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="Hello 我是第一個(gè)子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="Hello 我是第二個(gè)子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="Hello 我是第三個(gè)子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="Hello 我是第四個(gè)子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="Hello 我是第五個(gè)子控件"?/>
</LinearLayout>

上圖橫向排列了五個(gè)控件,并且線性布局不會(huì)自動(dòng)換行,當(dāng)控件超出屏幕邊緣,后面的控件就被隱藏,不會(huì)被顯示出來(lái)。

LinearLayout基本屬性

android:gravity:用來(lái)控制子控件的位置,值有top,left,right,bottom,center,分別表示子控件在頂部、左部、右部、下部、垂直方向居中并且水平方向居中,值得注意的是,還可以組合取值,如right|center_vertical表示子控件在右部并且垂直方向居中;

android:orientation:用來(lái)控制子控件的排列方式,值為horizontal時(shí)表示所有子控件橫向排列,為vertical時(shí)表示所有子控件豎向排列,上面的例子是橫向排列,我們來(lái)試試豎向排列;

把a(bǔ)ndroid:orientation改為vertical,為了使效果更明顯,我們?nèi)サ鬭ndroid:gravity設(shè)置,使用默認(rèn)值(top|left),運(yùn)行如下:

源碼鏈接:https://yunjunet.cn/876750.html

Android開(kāi)發(fā)學(xué)習(xí)教程(12)- Android布局之線性布局LinearLayout的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
泰顺县| 大兴区| 凤凰县| 靖边县| 华池县| 上高县| 许昌县| 灵璧县| 张家港市| 孝昌县| 龙川县| 京山县| 宜黄县| 彭水| 台安县| 环江| 页游| 祁连县| 太谷县| 东乡族自治县| 和硕县| 平遥县| 湖口县| 肃宁县| 泸州市| 灌南县| 祁连县| 库尔勒市| 汉沽区| 沙坪坝区| 龙江县| 会理县| 慈溪市| 陆川县| 河北省| 鹤壁市| 韩城市| 高碑店市| 大悟县| 荆州市| 庆阳市|