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

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

Android開發(fā)學(xué)習(xí)教程(15)- Android布局之幀布局FrameLayout

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

—— If not me, who? If not now, when?

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

幀布局是什么

幀布局中的控件只能通過layout_gravity來控制控件的位置,如果不設(shè)置layout_gravity屬性所有控件都會(huì)按照添加順序一個(gè)一個(gè)的堆在幀布局的左上角。相同層級(jí)布局中 FrameLayout的效率也是最高的,占用內(nèi)存相對來說也是較小的(具體原因在后續(xù)篇章會(huì)詳細(xì)講)。

幀布局有什么用

通過layout_gravity控制控件在屏幕的位置。

幀布局怎么用

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

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
<?xml?version="1.0"?encoding="utf-8"?>
<FrameLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:layout_width="match_parent"
????android:layout_height="match_parent">
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="我是第一個(gè)子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_gravity="center_horizontal"
????????android:text="我是第二個(gè)子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_gravity="right"
????????android:text="我是第三個(gè)子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_marginTop="40dp"
????????android:text="我是第四個(gè)子控件"?/>
????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_marginTop="80dp"
????????android:text="我是第五個(gè)子控件"?/>
</FrameLayout>

第一個(gè)控件

1
2
3
4
<TextView
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:text="我是第一個(gè)子控件"?/>

沒有設(shè)置任何屬性,控件默認(rèn)顯示在FrameLayout左上角

第二個(gè)控件

1
2
3
4
5
<TextView
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:layout_gravity="center_horizontal"
????android:text="我是第二個(gè)子控件"?/>

屬性android:layout_gravity=”center_horizontal”表示TextView控件位于FrameLayout的水平居中位置

第三個(gè)控件

1
2
3
4
5
<TextView
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:layout_gravity="right"
????android:text="我是第三個(gè)子控件"?/>

屬性android:layout_gravity=” right “表示TextView控件位于FrameLayout的最右邊

第四個(gè)控件

1
2
3
4
5
<TextView
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:layout_marginTop="40dp"
????android:text="我是第四個(gè)子控件"?/>

屬性android:layout_marginTop=”40dp”表示TextView控件距離FrameLayout頂部40dp,同理,第五個(gè)控件距離FrameLayout頂部80dp

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

Android開發(fā)學(xué)習(xí)教程(15)- Android布局之幀布局FrameLayout的評(píng)論 (共 條)

分享到微博請遵守國家法律
长沙县| 绥芬河市| 峡江县| 汤阴县| 罗定市| 高清| 长丰县| 昆山市| 龙泉市| 文成县| 静乐县| 高淳县| 馆陶县| 余庆县| 罗田县| 克什克腾旗| 钟山县| 安陆市| 盖州市| 苏尼特右旗| 政和县| 尉犁县| 迁西县| 香港| 宾阳县| 安图县| 施秉县| 惠东县| 鹤峰县| 孟州市| 共和县| 安龙县| 乐亭县| 宣城市| 安远县| 富民县| 基隆市| 花莲市| 龙州县| 库尔勒市| 海南省|