在帧布局管理中,每加入一个组件,都将建立一个空白的区域,一般称为帧,这些帧都会根据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