代码如下
<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/id_title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="layout_constraintHorizontal_chainStyle的使用"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/id_constraint_layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/id_title1"
app:layout_constraintLeft_toLeftOf="parent"
>
<TextView
android:id="@+id/id_textview1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="textview1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/id_textview2"
app:layout_constraintHorizontal_chainStyle="spread_inside"
android:background="@color/colorAccent"
/>
<TextView
android:id="@+id/id_textview2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="textview2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/id_textview1"
app:layout_constraintRight_toLeftOf="@id/id_textview3"
android:background="@color/colorPrimary"
/>
<TextView
android:id="@+id/id_textview3"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="textview3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/id_textview2"
app:layout_constraintRight_toRightOf="parent"
android:background="@color/colorPrimaryDark"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/id_title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="layout_constraintHorizontal_weight的使用"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/id_constraint_layout1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/id_constraint_layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@+id/id_title2"
app:layout_constraintHorizontal_weight="1"
>
<TextView
android:id="@+id/id_textview4"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="小欢喜"
android:background="@color/colorPrimaryDark"
app:layout_constraintHorizontal_weight="0.3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/id_textview5"
/>
<TextView
android:id="@+id/id_textview5"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="笑哈哈"
android:background="@color/colorPrimary"
app:layout_constraintHorizontal_weight="0.6"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/id_textview4"
app:layout_constraintRight_toRightOf="@id/id_textview6"
/>
<TextView
android:id="@+id/id_textview6"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="美滋滋"
android:background="@color/colorAccent"
app:layout_constraintHorizontal_weight="0.6"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/id_textview5"
app:layout_constraintRight_toRightOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
完事!!!嘚嘚嘚