效果图:
关键代码:android:layout_width="0dp",0dp在ConstraintLayout中的含义是match_constraint。
完整代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="@+id/rl_left"
android:layout_width="0dp"
android:layout_height="200dp"
android:background="#00ff00"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/rl_right"
app:layout_constraintTop_toTopOf="parent" />
<RelativeLayout
android:id="@+id/rl_right"
android:layout_width="0dp"
android:layout_height="200dp"
android:background="#ff0000"
app:layout_constraintLeft_toRightOf="@id/rl_left"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
版权声明:本文为zhangjin1120原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。