android约束布局的好处,Android约束布局ConstraintLayout详解

博客展示了Android约束布局的相关代码,包含多个文本视图和一个图像视图的布局设置,如通过app:layout_constraint系列属性设置视图的位置关系,最后给出了运行结果。

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

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/text1"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:background="@android:color/holo_red_light"

android:text="1"

android:textSize="20dp"

app:layout_constraintLeft_toLeftOf="parent" />

android:id="@+id/text2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@android:color/holo_blue_light"

android:text="2"

android:textSize="20dp"

app:layout_constraintLeft_toRightOf="@+id/text1" />

android:id="@+id/text3"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:background="@android:color/holo_green_light"

android:text="3"

android:textSize="20dp"

app:layout_constraintTop_toBottomOf="@+id/text1" />

android:id="@+id/text4"

android:layout_width="200dp"

android:layout_height="wrap_content"

android:background="@android:color/holo_orange_light"

android:text="4"

android:textSize="20dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@android:color/darker_gray"

android:src="@mipmap/ic_launcher"

app:layout_constraintBottom_toTopOf="@id/text4"

app:layout_constraintLeft_toRightOf="@id/text2" />

运行结果:

fff6c98081bf8904098fb5e1bd59ff4b.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值