Android-佈局管理-幀佈局

簡要概述:

    在幀佈局管理中,每加入一個組件,都將建立一個空白的區域,一般稱爲幀,這些幀都會根據gravity屬性執行自動對齊。默認狀況下,幀佈局從屏幕的左上角(0,0)座標點開始佈局,多個組件層疊排序,後面的組件覆蓋前面的組件。其基本的語法格式以下:android

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    屬性列表>
</FrameLayout>

    FrameLayout支持的經常使用XML屬性以下:佈局

xml屬性 描述
android:foreground 設置該幀佈局容器的前景圖像
android:foregroundGravity 定義繪製前景圖像的gravity屬性,即前景圖像顯示的位置。

樣例代碼清單:

<?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"
    android:foreground="@drawable/test"
    android:foregroundGravity="bottom|right">

    <TextView
        android:text="紅色TextView"
        android:layout_width="700px"
        android:layout_height="700px"
        android:layout_gravity="center"
        android:background="#FF00"/>

    <TextView
        android:text="綠色TextView"
        android:layout_width="500px"
        android:layout_height="500px"
        android:layout_gravity="center"
        android:background="#0f0"/>
    <TextView
        android:text="紫色TextView"
        android:layout_width="300px"
        android:layout_height="300px"
        android:layout_gravity="center"
        android:background="#ff0f"/>

</FrameLayout>

效果以下:spa