Android佈局(3)--幀佈局(FrameLayout)

  在幀佈局中,每添加一個組件都將創建一個空白區域,通稱之爲一幀。這些幀都要被對齊到屏幕左上角,不能單獨爲子組件指定位置。第一個添加到幀佈局中的子組件顯示在最底層,最後一個添加的子組件位於最頂層,上一層的子組件會覆蓋下一層的子組件,這種顯示方法類似於堆棧。因此又稱爲堆棧佈局。 

  幀佈局的大小由子組件中尺寸最大的子組件來決定。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.demo.FrameLayout">

    <TextView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:id="@+id/textView1"
        android:background="#FFD700"
        android:text="第一行"
        android:gravity="bottom"
        android:textSize="12pt"/>
    <TextView
        android:layout_width="260dp"
        android:layout_height="260dp"
        android:id="@+id/textView2"
        android:background="#FFA07A"
        android:text="第二行"
        android:gravity="bottom"
        android:textSize="14pt"/>
    <TextView
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:id="@+id/textView3"
        android:text="第三行"
        android:background="#FF00FF"
        android:textSize="16pt"/>
    <TextView
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:id="@+id/textView4"
        android:background="#FF0000"
        android:text="第四行"
        android:gravity="bottom"
        android:textSize="16pt"/>
</FrameLayout>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章