ConstraintLayout не ограничивается дном, когда скрытое подчиненное становится скрытым - PullRequest
0 голосов
/ 21 февраля 2019

Я попытался сделать название как можно более описательным.У меня есть ConstraintLayout с двумя LinearLayout детьми, у которых ScrollView внутри, так как внутри много вещей.Каждый дочерний элемент имеет вес 1. Макет имеет ограничения сверху панели инструментов, снизу, слева и справа от родителя и поля сверху.В общем, этот макет действует как нижний лист, который скользит вверх и вниз.Оба вложенных представления (LinearLayouts -s) могут быть "расширены", и в этом случае другой вспомогательный вид изменяет свою видимость на gone.

Итак, что происходит, когда я раскрываю один макет и скрываю другой, по какой-то причине выравнивание всего макета остается сверху родительского элемента, сохраняя поле, но сокращается до дна, оставляя пустое пространство.Я хочу, чтобы он переместился в нижнюю часть экрана именно в таком случае.Я также добавил app:layout_constraintVertical_bias="1.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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?ord_canvas_secondary_color">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar">

        <include layout="@layout/merge_screen_container" />

    </FrameLayout>

    <View
        android:id="@+id/dim_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="0.5"
        android:background="@color/ord_black"
        android:clickable="true"
        android:focusable="true"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

    <FilterSheet
        android:id="@+id/subscriptions_filter"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="@dimen/dim_8x"
        android:layout_marginTop="@dimen/dim_56x"
        android:layout_marginEnd="@dimen/dim_8x"
        android:layout_marginBottom="@dimen/dim_8x"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar"
        app:layout_constraintVertical_bias="1.0" />

</android.support.constraint.ConstraintLayout>

enter image description here

enter image description here

Ответы [ 3 ]

0 голосов
/ 21 февраля 2019

Это должно работать.Пожалуйста, попробуйте.

<?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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?ord_canvas_secondary_color">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar">

        <include layout="@layout/merge_screen_container" />

    </FrameLayout>

    <View
        android:id="@+id/dim_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="0.5"
        android:background="@color/ord_black"
        android:clickable="true"
        android:focusable="true"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

    <android.support.constraint.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar"
        app:layout_constraintVertical_bias="1.0" >
        <FilterSheet
            android:id="@+id/subscriptions_filter"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginStart="@dimen/dim_8x"
            android:layout_marginTop="@dimen/dim_56x"
            android:layout_marginEnd="@dimen/dim_8x"
            android:layout_marginBottom="@dimen/dim_8x"
            android:visibility="invisible"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            />
    </android.support.constraint.ConstraintLayout>


</android.support.constraint.ConstraintLayout>
0 голосов
/ 21 февраля 2019

Итак, ответ от @Arti Patel вроде работал, но представление фильтра все равно выходило бы за пределы панели инструментов.В итоге я использовал LinearLayout и FrameLayout.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="?ord_canvas_secondary_color"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <include layout="@layout/merge_screen_container" />

    </LinearLayout>

    <View
        android:id="@+id/dim_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="0.5"
        android:background="@color/ord_black"
        android:clickable="true"
        android:focusable="true"
        android:visibility="gone" />

    <FilterSheet
        android:id="@+id/subscriptions_filter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginStart="@dimen/dim_8x"
        android:layout_marginTop="@dimen/filter_margin_top"
        android:layout_marginEnd="@dimen/dim_8x"
        android:layout_marginBottom="@dimen/dim_8x"
        android:visibility="invisible" />

</FrameLayout>
0 голосов
/ 21 февраля 2019

Попробуйте это

<?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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?ord_canvas_secondary_color">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="0dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar">

        <include layout="@layout/merge_screen_container" />

    </FrameLayout>

    <View
        android:id="@+id/dim_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:alpha="0.5"
        android:background="@color/ord_black"
        android:clickable="true"
        android:focusable="true"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

    <FilterSheet
        android:id="@+id/subscriptions_filter"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="@dimen/dim_8x"
        android:layout_marginTop="@dimen/dim_56x"
        android:layout_marginEnd="@dimen/dim_8x"
        android:layout_marginBottom="@dimen/dim_8x"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

</android.support.constraint.ConstraintLayout>
...