商務(wù)網(wǎng)站建設(shè)管理思路青島seo經(jīng)理
一、FrameLayout(幀布局)概述
????????FrameLayout又稱作幀布局,它相比于LinearLayout和RelativeLayout要簡(jiǎn)單很多,因?yàn)樗膽?yīng)用場(chǎng)景也少了很多。這種布局沒(méi)有方便的定位方式,所有的控件都會(huì)默認(rèn)擺放在布局的左上角。
示例1代碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><FrameLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:width="300px"android:height="300px"android:background="#aa0000" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:width="200px"android:height="200px"android:background="#00aa00" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:width="100px"android:height="100px"android:background="#0000aa" /></FrameLayout></LinearLayout>
效果圖1:
?從布局中可以看出,紅色、綠色、藍(lán)色是依次藍(lán)色在綠色上面,綠色在紅色上面,因此可以得出FeameLayout中的控件都會(huì)默認(rèn)擺放在布局的左上角。
????????當(dāng)然除了這種默認(rèn)效果之外,我們還可以使用android:layout_gravity屬性來(lái)指定控件在布局中的對(duì)齊方式,這和LinearLayout中的用法是相似的。
示例2:
<?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"><ImageViewandroid:id="@+id/iv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:src="@mipmap/ic_launcher" /><TextViewandroid:id="@+id/tv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="left"android:text="This is TextView" /></FrameLayout>
效果圖2: