框架布局
框架布局是最简单的布局方式,所有添加到这个布局中的视图都是以层叠的方式显示。第一个添加到框架布局中的视图显示在最底层,最后一个呗放在最顶层,上一层的视图会覆盖下一层的视图,因此框架布局类似堆栈布局。
属性值 | 描述 |
---|---|
top | 将试图放到屏幕的顶端 |
Bottom | 将视图放到屏幕的底端 |
Left | 将视图放在屏幕的左侧 |
Right | 将视图放在屏幕的右侧 |
Center_vertical | 将视图按照垂直方向居中显示 |
horizontal_vertical | 将视图按照水平方向居中显示 |
例如:图片的层叠放置
<?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"
tools:context="com.example.FrameLayout.FrameLayoutActivity">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/frame_background"
android:scaleType="fitCenter"
android:layout_gravity="center"
/>
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:background="@drawable/frame_person_bg"
android:layout_marginTop="100dp"/>
</FrameLayout>
运行效果图