帖布局

帖布局:

在帖布局管理器中,每加入一个组件,都将创建一个空白的区域,通常称为一帖,这些帖大都汇被放置在屏幕的左上角,即帖布局是从左上角(0,0)坐标点开始布局。多个组件层叠排序,后面的组件覆盖前面的组件。

例子:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/myLayout"
    tools:context=".MainActivity">
    <TextView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:text="绿色"
        android:background="#1047df"/>
    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:text="蓝色"
        android:background="#33dcd6"/>
    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:text="紫色"
        android:background="#c70ec1"/>
</FrameLayout>

帖布局
只需加一条属性就能实现各控件垂直居中:
android:layout_gravity=“center”
帖布局

另外,FrameLayout还有两个常用的属性,分别是foreground(前景):即不会被覆盖;

foregroundGravity:设置前景的显示位置