五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

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

Android開發(fā)學(xué)習(xí)教程(14)- Android布局之相對布局RelativeLayout

2023-01-27 16:07 作者:ChatGPT云炬學(xué)長  | 我要投稿

—— 珍貴的東西往往數(shù)目稀少,所以你要變得更強,才有力量去搶。

上一篇我們講了線性布局LinearLayout的基本用法,這里來學(xué)習(xí)常用布局之相對布局RelativeLayout的基本用法。

相對布局是什么

相對布局按照控件間的相對位置排列,比如控件A相對于控件B在控件B的左邊,并且和控件B頂部對齊等。

相對布局有什么用

通過相對位置來控制控件在屏幕的位置。

相對布局怎么用

繼續(xù)基于上一篇的項目,我們新建一個RelativeLayoutActivity:

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
37
38
39
40
41
42
43
<?xml?version="1.0"?encoding="utf-8"?>
<RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:layout_width="match_parent"
????android:layout_height="match_parent">
????<TextView
????????android:id="@+id/tv1"
????????android:layout_width="wrap_content"
????????android:layout_height="100dp"
????????android:layout_centerInParent="true"
????????android:background="#F0F0F0"
????????android:gravity="center"
????????android:text="我是第一個子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_alignTop="@+id/tv1"
????????android:layout_toLeftOf="@+id/tv1"
????????android:text="我是第二個子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_alignTop="@+id/tv1"
????????android:layout_toRightOf="@+id/tv1"
????????android:text="我是第三個子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_alignBottom="@+id/tv1"
????????android:layout_toLeftOf="@+id/tv1"
????????android:text="我是第四個子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_alignBottom="@+id/tv1"
????????android:layout_toRightOf="@+id/tv1"
????????android:text="我是第五個子控件"?/>
</RelativeLayout>

第一個控件

1
2
3
4
5
6
7
8
<TextView
????android:id="@+id/tv1"
????android:layout_width="wrap_content"
????android:layout_height="100dp"
????android:layout_centerInParent="true"
????android:background="#F0F0F0"
????android:gravity="center"
????android:text="我是第一個子控件"?/>
1
2
3
android:layout_height="100dp":表示TextView控件高度為100dp
android:layout_centerInParent="true":表示TextView控件位于父控件RelativeLayout的水平居中并且垂直居中
android:gravity="center":表示TextView控件上面顯示的內(nèi)容水平居中并且垂直居中

第二個控件

1
2
3
4
5
6
<TextView
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:layout_alignTop="@+id/tv1"
????android:layout_toLeftOf="@+id/tv1"
????android:text="我是第二個子控件"?/>
1
2
android:layout_alignTop="@+id/tv1":表示與id為tv1控件頂部對齊
android:layout_toLeftOf="@+id/tv1":表示在id為tv1控件的左邊

第三個控件

1
2
3
4
5
6
<TextView
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:layout_alignTop="@+id/tv1"
????android:layout_toRightOf="@+id/tv1"
????android:text="我是第三個子控件"?/>
1
2
android:layout_alignTop ="@+id/tv1"表示與id為tv1控件頂部對齊
android:layout_toRightOf ="@+id/tv1"表示在id為tv1控件的右邊

第四個控件

1
2
3
4
5
6
<TextView
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:layout_alignBottom="@+id/tv1"
????android:layout_toLeftOf="@+id/tv1"
????android:text="我是第四個子控件"?/>
1
2
android:layout_alignBottom="@+id/tv1"表示與id為tv1控件底部對齊
android:layout_toLeftOf="@+id/tv1"表示在id為tv1控件的左邊

第五個控件

1
2
3
4
5
6
<TextView
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:layout_alignBottom="@+id/tv1"
????android:layout_toRightOf="@+id/tv1"
????android:text="我是第五個子控件"?/>
1
2
android:layout_alignBottom="@+id/tv1"表示與id為tv1控件底部對齊
android:layout_toRightOf="@+id/tv1"表示在id為tv1控件的右邊

RelativeLayout常用基本屬性

第一類屬性 屬性值為true或者false

1
2
3
4
5
6
7
8
9
10
11
12
13
android:layout_centerHrizontal:水平居中
android:layout_centerVertical:垂直居中
android:layout_centerInparent:相對于父控件完全居中
android:layout_alignParentBottom:貼緊父控件的下邊緣
android:layout_alignParentLeft:貼緊父控件的左邊緣
android:layout_alignParentRight:貼緊父控件的右邊緣
android:layout_alignParentTop:貼緊父控件的上邊緣

第二類屬性 屬性值必須為id的引用名“@id/id-name”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
android:layout_below:在某控件下方
android:layout_above:在某控件上方
android:layout_toLeftOf:在某控件的左邊
android:layout_toRightOf:在某控件的右邊
android:layout_alignTop:本控件的上邊緣和某控件的上邊緣對齊
android:layout_alignLeft:本控件的左邊緣和某控件的左邊緣對齊
android:layout_alignBottom:本控件的下邊緣和某控件的下控件對齊
android:layout_alignRight:本控件的右邊緣和某控

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

Android開發(fā)學(xué)習(xí)教程(14)- Android布局之相對布局RelativeLayout的評論 (共 條)

分享到微博請遵守國家法律
汾阳市| 静安区| 天水市| 肇州县| 独山县| 申扎县| 九龙坡区| 松滋市| 嘉荫县| 江西省| 绵阳市| 扶沟县| 萝北县| 江孜县| 连州市| 泰和县| 铅山县| 南靖县| 荣成市| 沽源县| 嵩明县| 德化县| 紫金县| 阿拉善左旗| 五指山市| 柳江县| 大荔县| 抚远县| 福泉市| 康平县| 巴南区| 喀喇沁旗| 吕梁市| 四会市| 凌源市| 宜章县| 比如县| 金平| 奈曼旗| 云和县| 富平县|