Android之FrameLayout(帧布局)

来源:互联网 发布:java工程师职业路线 编辑:程序博客网 时间:2024/06/05 07:53

重点

FrameLayout(帧布局)可以说是最简单的布局了,我们添加控件时会默认把控件放到屏幕的左上角,后续添加的会把上一个覆盖,我们可以通过layout_gravity来移动控件。

属性

android:foreground:设置改帧布局容器的前景图像
android:foregroundGravity:设置前景图像显示的位置

那么前景图像是什么呢?和字面意思一样,是在布局最上方不会被覆盖的图像。


布局代码:

<?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" >    <TextView        android:layout_width="200dp"        android:layout_height="200dp"        android:background="#FF0000" />    <TextView        android:layout_width="150dp"        android:layout_height="150dp"        android:background="#000000" />    <TextView        android:layout_width="100dp"        android:layout_height="100dp"        android:background="#FFFFFF" /></FrameLayout>

效果图:
FrameLayout