Как центрировать пару представлений внутри ConstraintLayout? - PullRequest
0 голосов
/ 06 июля 2018

Как мне центрировать пару Views внутри ConstraintLayout, как показано ниже, без вложенности ? Они должны быть соприкасающимися и центрированными как единое целое.

enter image description here

Я пытался привязать их друг к другу и их родителям, но потом они не соприкасались друг с другом, поэтому я добавил горизонтальное смещение для обоих, но это не помогло.

Заранее спасибо ...

<ImageView
    android:id="@+id/imageView"
    android:layout_width="14dp"
    android:layout_height="14dp"
    android:scaleType="fitXY"        
    android:src="@drawable/checkmark"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@id/textView"/>

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/some_text"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toRightOf="@id/imageView"
    app:layout_constraintRight_toRightOf="parent"/>

1 Ответ

0 голосов
/ 06 июля 2018

Вам необходимо установить атрибут цепочки для заголовка цепочки, который является первым View слева в горизонтальной цепочке. Стиль, который даст ожидаемый результат - packed. В этом случае смещение не понадобится.

<ImageView
    android:id="@+id/imageView"
    android:layout_width="14dp"
    android:layout_height="14dp"
    android:scaleType="fitXY"
    android:src="@drawable/checkmark"
    app:layout_constraintHorizontal_chainStyle="packed"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@id/textView"/>

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/some_text"
    app:layout_constraintLeft_toRightOf="@id/imageView"
    app:layout_constraintRight_toRightOf="parent"/>
...