Как привязать BackDrop к низу экрана? | BottomSheetBehavior | Kotlin

Как мне привязать BottomSheet к низу экрана? А то, когда я листаю до самого низа, то у меня появляется пустое простанство. Глянул через Layout Inspector и это вина первого ConstraintLayout.

Есть xml фрагмент:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark">

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

    <ImageView
        android:id="@+id/image"
        android:layout_width="160dp"
        android:layout_height="220dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:src="@drawable/ic_placeholder"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/genre"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/marker_v2"
        android:gravity="start|center_horizontal"
        android:paddingLeft="4dp"
        android:paddingRight="4dp"
        android:text="@string/simple_genre"
        android:textColor="@color/white"
        app:fontFamily="@font/oswald"
        app:layout_constraintStart_toEndOf="@+id/image"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:text="@string/simple_ongoing_title"
        android:textColor="@color/white"
        android:textSize="18sp"
        app:fontFamily="@font/montserrat"
        app:layout_constraintStart_toEndOf="@+id/image"
        app:layout_constraintTop_toBottomOf="@+id/genre" />

    <TextView
        android:id="@+id/author"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:text="@string/title_notifications"
        android:textColor="@color/sky"
        android:textSize="12sp"
        app:layout_constraintStart_toEndOf="@+id/image"
        app:layout_constraintTop_toBottomOf="@+id/title" />
</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/contentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="16dp"
    android:background="@drawable/book_second_layout"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/image">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="MissingConstraints">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:background="@drawable/book_second_layout"
            android:orientation="vertical"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            tools:ignore="MissingConstraints">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="4dp"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/imageView5">

                <TextView
                    android:id="@+id/textView25"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal|left"
                    android:text="@string/Comments"
                    android:textColor="@color/black"
                    android:textSize="18sp"
                    app:fontFamily="@font/oswald"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:ignore="RtlHardcoded" />

                <TextView
                    android:id="@+id/textView26"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:drawableRight="@drawable/ic_baseline_arrow_forward_ios_24"
                    android:gravity="center_vertical"
                    android:text="46 Комментариев"
                    android:textSize="10sp"
                    app:fontFamily="@font/montserrat"
                    app:layout_constraintBottom_toTopOf="@+id/commentsRecycler"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:ignore="SmallSp" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/commentsRecycler"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textView25" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

А это в коде:

val contentLayout: ConstraintLayout? = root?.findViewById(R.id.contentLayout)

    val sheetBehavior = contentLayout?.let { BottomSheetBehavior.from(it) }
    sheetBehavior?.isFitToContents = false
    sheetBehavior?.isHideable = false

    sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED

введите сюда описание изображения


Ответы (1 шт):

Автор решения: Sire IMPACTUS

Проблема была в отступе, что я назначил второму ConstraintLayout. Убрав его, все решилось. А привязать BackDrop невозможно, т.к. он основан на CoordinatorLayout, который по своей суте похож на FrameLayout.

→ Ссылка