Стоп пустой ConstraintLayout от максимального растяжения - PullRequest
0 голосов
/ 18 ноября 2018

Когда я удаляю все виды из моего макета Constraint, я хочу, чтобы он имел высоту 0dp (как звучит wrap_content), но он растягивается как можно больше.

Есть ли документированный способ сделать это? Я имею в виду помимо установки maxHeight на 0 или скрытия.

Я пробовал app:layout_constrainedHeight="true" с "wrap_content", но это не работает.

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

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constrainedHeight="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

</android.support.constraint.ConstraintLayout>

1 Ответ

0 голосов
/ 18 ноября 2018

Мне не удалось найти правильное решение.


Самый простой способ, который я нашел, - добавить дополнительный вид с помощью height=0 и никогда не удалять его:

<?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.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_red_dark"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <FrameLayout
            android:id="@+id/somethingWithNoHeight"
            android:layout_width="match_parent"
            android:layout_height="0dp" />

        <!--<TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lorem ipsum" />-->
    </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

Я считаю, что вы должны заполнить ошибку, чтобы быть уверенным, что разработчики знают о такой проблеме

...