Как дать максимальную высоту, насколько это возможно, видам, которые выровнены по вертикали, и сохранить эти виды на одной высоте? - PullRequest
0 голосов
/ 19 марта 2019

У меня есть три ImageView, представляющих карты, которые связаны вертикально. Поверх них у меня есть TextView, а под ними кнопка. Вы можете видеть, что я имею в виду здесь: https://imgur.com/a/jVvR5xC

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

Ответы [ 2 ]

1 голос
/ 19 марта 2019

Если у вас уже есть 3 элемента с вертикальной цепью, все, что вам нужно сделать, - объявить высоту 3-х изображений в качестве ограничения соответствия или 0dp:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:text="This is the top text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="This is the bottom text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:text="Button"
        app:layout_constraintBottom_toTopOf="@+id/button3"
        app:layout_constraintEnd_toEndOf="@+id/button2"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="@+id/button2"
        app:layout_constraintTop_toBottomOf="@+id/button2" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:text="Button"
        app:layout_constraintBottom_toTopOf="@+id/button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView4"
        app:layout_constraintVertical_chainStyle="spread" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:text="Button"
        app:layout_constraintBottom_toTopOf="@+id/textView5"
        app:layout_constraintEnd_toEndOf="@+id/button"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="@+id/button"
        app:layout_constraintTop_toBottomOf="@+id/button" />
</androidx.constraintlayout.widget.ConstraintLayout>
0 голосов
/ 19 марта 2019

использовать линейный макет в качестве родительского вида, а ориентация = вертикальная. внутри линейного макета используйте вид карты. установите layout_weight = 1 для каждого вида карты.

...