Fragment 中 BottomNavigation 和 Scrollview 的问题

Problems with BottomNavigation and Scrollview in Fragment

所以我想创建一个应用程序,它有一个底部导航栏和一个包含托管一些卡片视图的滚动视图的片段。现在的问题是,无论我尝试什么,我都无法让 Scrollview 滚动。我已经尝试过使用 Nestedscrollview,甚至切换到 Recyclerview,两者都存在不可滚动的相同问题。

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        app:layout_constraintBottom_toTopOf="@+id/nav_view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:itemIconTint="@drawable/bottom_navigation_selector"
        app:itemTextColor="@drawable/bottom_navigation_text_selector"
        app:layout_constraintBottom_toBottomOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <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:layout_constraintBottom_toTopOf="@+id/nav_view"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:navGraph="@navigation/mobile_navigation"
        tools:layout_editor_absoluteX="0dp" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="58dp"
        app:layout_constraintBottom_toTopOf="@+id/nav_view"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

fragment_home.xml:

<androidx.core.widget.NestedScrollView 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="wrap_content"
    android:clipToPadding="false"
    android:fillViewport="false"
    android:padding="16dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <androidx.cardview.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="16dp"
            app:cardCornerRadius="10dp"
            app:cardElevation="2dp">

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

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="16dp"
            app:cardCornerRadius="10dp"
            app:cardElevation="2dp">

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


        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_margin="16dp"
            app:cardCornerRadius="10dp"
            app:cardElevation="2dp">

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

        </androidx.cardview.widget.CardView>
    </LinearLayout>


</androidx.core.widget.NestedScrollView> 

我实际上很困惑,因为当然有很多应用程序将底部导航栏与包含滚动视图的片段结合使用,但我仍然无法在任何地方找到这个问题。可能我遗漏了一些明显的东西。 预先感谢您的回答!

您是否尝试添加明确的 ScrollView 大小?

在您的 ScrollView 碎片上:

android:layout_height="wrap_content"

android:layout_height="300dp"

事实证明这是一个不必要的列表视图(activity_main.xml 中的最后一个)我认为这是底部导航模板的标准但我仍然不知道它是如何结束的。它基本上阻止了 Fragments 上所有可滚动的内容。我花了几个小时才搞清楚这个问题。