CoordinatorLayout 中的 NestedScrollView 和 AppBarLayout:无法滚动到 NestedScrollView 结束

NestedScrollView and AppBarLayout in a CoordinatorLayout: inability to scroll until the end of NestedScrollView

我有一个 activity 布局,包括:

XML 文件如下:

<?xml version="1.0" encoding="utf-8"?>
<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:fillViewport="true">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorWhite"
            app:contentInsetEnd="0dp"
            app:contentInsetStart="0dp"
            app:layout_scrollFlags="enterAlways"
            app:popupTheme="@style/Theme.AppCompat.Light">

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

                <ImageView
                    android:id="@+id/backButton"
                    style="@style/Icon"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginBottom="16dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_2" />

                <View
                    android:id="@+id/view13"
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginBottom="16dp"
                    android:background="@drawable/bg_white_ellipse_with_border"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toEndOf="@+id/backButton"
                    app:layout_constraintTop_toTopOf="parent" />

                <ImageView
                    android:id="@+id/imageView21"
                    style="@style/Icon"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginBottom="16dp"
                    app:layout_constraintBottom_toBottomOf="@+id/view13"
                    app:layout_constraintStart_toStartOf="@+id/view13"
                    app:layout_constraintTop_toTopOf="@+id/view13"
                    app:srcCompat="@drawable/ic_1" />

                <EditText
                    android:id="@+id/searchField"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:background="@color/fui_transparent"
                    android:ems="10"
                    android:hint="Type something"
                    android:imeOptions="actionSearch"
                    android:inputType="text"
                    android:maxLines="1"
                    app:layout_constraintBottom_toBottomOf="@+id/view13"
                    app:layout_constraintStart_toEndOf="@+id/imageView21"
                    app:layout_constraintTop_toTopOf="@+id/view13" />

            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.appcompat.widget.Toolbar>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:id="@+id/scrollView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <View
                android:id="@+id/view8"
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="@color/colorLightGray"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <View
                android:id="@+id/view9"
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="@color/colorLightGray"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/rv1" />

            <View
                android:id="@+id/view12"
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:layout_marginBottom="16dp"
                android:background="@color/colorLightGray"
                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/rv2" />

            <TextView
                android:id="@+id/textView21"
                style="@style/HeadingText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:text="Dishes"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view8" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:nestedScrollingEnabled="false"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView21" />

            <TextView
                android:id="@+id/textView8"
                style="@style/HeadingText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:text="Restaurants"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view9" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="@+id/view12"
                app:layout_constraintTop_toBottomOf="@+id/textView8" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

工具栏如我所愿固定在页面顶部。一切都正确滚动。但是,我无法滚动到 NestedScrollView 的末尾,即该项目被切断,我无法滚动到第二个 RecyclerView 中的最后一个项目。我该如何解决这个问题?

由于某种原因,CoordinatorLayout 上的此属性 android:fillViewport="true" 导致其损坏。删除该属性可以纠正所有问题。