在 spread-chain ConstraintLayout 中打包两个相邻的视图

Pack two adjacent views in a spread-chain ConstraintLayout

我有一组在 ConstraintLayout 中的展开链中链接在一起的六个小部件。此视图中没有其他布局,只有 ConstraintLayout 和小部件。

中间的两个小部件应该靠得更近一些,因为一个是另一个的标题:

widget-title
widget-EditText

我想在我视图中的所有小部件上使用展开链(垂直居中),但我特别希望将这两个小部件垂直打包在一起,同时尊重顶部和顶部的底部边距底部的边距。

我不知道该怎么做。我尝试将它们放在一起作为垂直 LinearLayout 的 children,但它拒绝正确参与传播链——它到达顶部并且许多其他小部件消失。

我已经尝试向这两个视图添加额外的约束,但传播链似乎覆盖了所有额外的约束并且它们没有效果。唯一的例外是对齐它们的基线,这确实有效但将它们混淆在一起,这是我不想要的。

我看不出有什么方法可以在同一个 ConstraintLayout 中创建多个分布链,使它们均匀分布。

如何将链中的两个(或更多)小部件分组,以便它们的传播规则与链的其余部分不同?或者失败了,你如何构建多个传播相同的链?

当您在 LinearLayout 中映射两个中心小部件时一定出了问题。以下布局就是这样做的,并且似乎按照我认为您想要的方式工作。我没有在链中添加很多View,但足以理解这个想法。看看吧。

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView1"
        app:layout_constraintBottom_toTopOf="@id/layout"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="spread" />

    <LinearLayout
        android:id="@+id/layout"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@id/textView4"
        app:layout_constraintTop_toBottomOf="@id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:text="TextView2" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="TextView3" />
    </LinearLayout>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView4"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/layout" />

</android.support.constraint.ConstraintLayout>