相对布局的使用

将素材图片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>

由于图片里的图像大小位置有差异所以要更改图片大小

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值