框架布局是将控件组织在Android程序的用户界面中最简单的布局类型之一。
框架布局中的子视图总是被绘制到相对于屏幕的左上角上。所有添加到这个布局中的视图都是以层叠的方式显示。第一个添加到框架布局中的视图显示在最底层,最后一个被放在最顶层,上一层的视图会覆盖下一层的视图,因此框架布局类似堆栈布局。
在框架布局中,常用的属性有以下几项:
android:top将视图放到屏幕的顶端
android:Buttom将视图放到屏幕的低端
android:Left将视图放到屏幕的左端
android:Right将视图放到屏幕的右端
android:Center_vertical将视图按照垂直方向居中显示
android:Center_horizontal将视图按照水平方向居中显示

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/background" > </ImageView> <ImageView android:layout_width="63dp" android:layout_height="46dp" android:layout_gravity="center" android:layout_marginTop="80dp" android:background="@drawable/img1" > </ImageView> <ImageView android:layout_width="85dp" android:layout_height="85dp" android:layout_gravity="center" android:layout_marginBottom="80dp" android:background="@drawable/img2" > </ImageView> </FrameLayout>