ConstraintLayout Android中的链接链

时间:2019-03-18 13:34:43

标签: android android-constraintlayout

如何在约束布局中链接多个不同样式(扩展,打包..)的链?

换句话说,如何在相同的轴(水平/垂直)上制作已经以不同样式链接的一组视图链?enter image description here

如图所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<Button
    android:id="@+id/view1"
    android:text="VIEW 1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/view2"/>
<Button
    android:id="@+id/view2"
    android:text="VIEW 2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/view1"
    app:layout_constraintBottom_toTopOf="@+id/view3"/>

<Button
    android:id="@+id/view3"
    android:text="VIEW 3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/view2"
    app:layout_constraintBottom_toTopOf="@+id/view4"/>

<Button
    android:id="@+id/view4"
    android:text="VIEW 4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/view3"
    app:layout_constraintBottom_toBottomOf="parent"/>

</android.support.constraint.ConstraintLayout>

Preview of current xml code:

1 个答案:

答案 0 :(得分:0)

为了实现“打包链的扩展链”,您首先以正常方式创建两个单独的打包链。我们称它们为chain1 和chain2。然后创建一个 <space>。现在像这样连接它们:chain1 end -> space, space -> chain2 start, chain2 start -> chain1 end。

Here is a more in depth explanation