安卓入门.RelativeLayout相对布局1

本文详细介绍了RelativeLayout相对布局的概念及其使用方法。通过示例展示了如何利用属性如@+id创建新的控件ID,@id引用已存在的控件ID,以及android:layout_toRightOf等属性来指定控件之间的相对位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


RelativeLayout相对布局

所谓相对布局,即第二个控件的摆放,为第一个控件的相对位置


<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="第一个"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00ff00"
android:text="第二个"
android:layout_toRightOf="@id/textView1"//控件摆放在id为textView1控件的右边
/>

@id,为引用一个已经创建好的控件id
@+id,为创建一个新的控件id


android:layout_toLeftOf 摆放在左边
android:layout_below 摆放在下边
android:layout_above 摆放在上边


android:layout_alignRight="@id/textView1"对齐到右边


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值