В макете ограничений Можно ли поместить 4 текстовых представления в цепочку Horizental с разным пространством между каждым видом? - PullRequest
1 голос
/ 06 марта 2020

В ConstraintLayout, возможно ли поместить 4 TextView с в горизонтальную цепочку с разным пространством между каждым видом?

Например, как на картинке ниже, и я хочу, чтобы на разных экранах положение TextView было одинаковым.

enter image description here

1 Ответ

1 голос
/ 06 марта 2020

Я могу придумать альтернативное решение без использования цепочки. Вы можете использовать Guideline для создания макета, который вы пытаетесь создать. Я создал один для вас. Дайте мне знать, если это поможет.

<?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">

    <android.support.constraint.Guideline
        android:id="@+id/guideline_right_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent=".9" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline_left_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent=".1" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline_top_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent=".1" />

    <TextView
        android:id="@+id/text_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text 1"
        android:textSize="20sp"
        app:layout_constraintStart_toStartOf="@+id/guideline_left_margin"
        app:layout_constraintTop_toBottomOf="@+id/guideline_top_margin" />

    <TextView
        android:id="@+id/text_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text 2"
        android:textSize="20sp"
        app:layout_constraintEnd_toStartOf="@+id/text_3"
        app:layout_constraintStart_toStartOf="@+id/text_1"
        app:layout_constraintTop_toBottomOf="@+id/guideline_top_margin" />

    <TextView
        android:id="@+id/text_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="16dp"
        android:text="Text 3"
        android:textSize="20sp"
        app:layout_constraintEnd_toStartOf="@+id/text_4"
        app:layout_constraintTop_toBottomOf="@+id/guideline_top_margin" />

    <TextView
        android:id="@+id/text_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text 4"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="@+id/guideline_right_margin"
        app:layout_constraintTop_toBottomOf="@+id/guideline_top_margin" />

</android.support.constraint.ConstraintLayout>

Вот как это выглядит в портретном режиме.

portrait

А вот так это выглядит в ландшафтном режиме.

landscape

...