将素材图片rabbit1、rabbit2、rabbit3、rabbit4、smile复制进drawable
新建relativelayout_demo.xml
完整代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"//插入图片
android:layout_width="80dp"
android:layout_height="80dp"//更改图像大小
android:layout_centerInParent="true"//首先确定父窗口的中间位置
app:srcCompat="@drawable/smile1" />
<ImageView //绿色兔子图片
android:id="@+id/imageView3"
android:layout_width="110dp"
android:layout_height="100dp"
android:layout_above="@+id/imageView4"//将本控件放在imageView4控件之上
android:layout_alignRight="@+id/imageView"//将控件的右边缘和imageView控件的右边缘对齐
app:srcCompat="@drawable/rabbit3" />
<ImageView //黄色兔子图片
android:id="@+id/imageView4"
android:layout_width="110dp"
android:layout_height="100dp"
android:layout_alignBottom="@+id/imageView"//将控件的底边缘和imageView控件的底边缘对齐
android:layout_toLeftOf="@+id/imageView3"//将控件的右边缘和imageView3控件的左边缘对齐
android:layout_toStartOf="@+id/imageView3"//本元素从imageView3元素开始
app:srcCompat="@drawable/rabbit4" />
<ImageView //粉色兔子图片
android:id="@+id/imageView5"
android:layout_width="110dp"
android:layout_height="100dp"
android:layout_a="@+id/imageView"
android:layout_below="@+id/imageView3"
android:layout_marginLeft="15dp"//离imageView左边缘的距离
android:layout_marginStart="15dp"
android:layout_toRightOf="@+id/imageView"//将控件的左边缘和imageView控件的右边缘对齐
app:srcCompat="@drawable/rabbit2" />
<ImageView //蓝色兔子图片
android:id="@+id/imageView6"
android:layout_width="110dp"
android:layout_height="100dp"
android:layout_below="@+id/imageView4"
android:layout_marginTop="27dp"//离imageView上边缘的距离
android:layout_toRightOf="@+id/imageView4"
app:srcCompat="@drawable/rabbit1"
/>
</RelativeLayout>
由于图片里的图像大小位置有差异所以要更改图片大小