1. 布局设定
两张图片就必须要有3个布局,一个作为主布局长宽与屏幕相同;两个子布局用于展示图片,布局上下分布
2. 创建主布局
<RelativeLayout 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=".MainActivity" >
</RelativeLayout>
3. 创建子布局
布局高度可以先设定一个值,再根据效果调试
4. 子布局上下分布
给子布局1添加id
android:id="@+id/pic"
设置子布局2在布局下方
android:layout_below="@id/pic"
整体代码:
<RelativeLayout 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=".MainActivity" >
<RelativeLayout
android:id="@+id/pic"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@drawable/pic"
></RelativeLayout>
<RelativeLayout
android:layout_below="@id/pic"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@drawable/pic1"
></RelativeLayout>
</RelativeLayout>