使用 NavHostFragment 显示 DialogFragment 显示为空

Displaying DialogFragment with NavHostFragment displays empty

我正在尝试显示一个 DialogFragment,它在出现在屏幕上后应该显示 NavHostFragment 中指定的 nav_graph 的起始目的地。这是 DialogFragment 布局:

<?xml version="1.0" encoding="utf-8"?>
<layout>

<!--    <androidx.constraintlayout.widget.ConstraintLayout -->
<!--        android:layout_width="match_parent"-->
<!--        android:layout_height="800dp">-->

<androidx.coordinatorlayout.widget.CoordinatorLayout 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">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:visibility="visible">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="8dp"
            android:orientation="vertical">

            <fragment
                android:id="@+id/nav_host_home_bottom_sheet"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:defaultNavHost="true"
                app:layout_constraintBottom_toTopOf="@+id/dismiss_registration_button"
                app:layout_constraintTop_toTopOf="parent"
                app:navGraph="@navigation/membership_navigation" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/dismiss_registration_button"
                style="@style/Widget.MaterialComponents.Button.TextButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/open_sans_regular"
                android:text="@string/all_dismiss"
                android:textSize="14sp"
                android:textStyle="bold"
                app:layout_constraintBottom_toBottomOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

<!--    </androidx.constraintlayout.widget.ConstraintLayout>-->

DialogFragment 中只显示 Dismiss 按钮。当我取消注释 ConstraintLayout 并将 layout_height 固定为 800dp 时,NavHostFragment 的 startDestination 加载正常。问题是我不想对 layout_height 进行 hadrcode - 如何在不对 layout_height 进行硬编码的情况下使用 CoordinatorLayou 或 ConstraintLayout 显示它?

为了让它工作,我只是将 DialogFragment 布局更改为

<?xml version="1.0" encoding="utf-8"?>
<layout>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/membership_navigation" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

然后在需要的地方处理滚动视图和其他片段。