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>


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