首页 > 解决方案 > NestedScrollview 不适用于 Drawerlayout

问题描述

我正在尝试在我的抽屉布局中添加嵌套滚动视图,但嵌套滚动视图不起作用,即我的视图没有向下滚动。我的内容主要布局应该是滚动布局。我的布局包含工具栏的线性布局和主屏幕的主要内容和导航视图。任何类型的帮助将不胜感激。这是我的 XML 文件代码:

<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activities.MainActivity">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:scrollbars="none">

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

            <include
                layout="@layout/drawer_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />


            <include
                layout="@layout/content_main"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />


        </LinearLayout>
    </androidx.core.widget.NestedScrollView>
    
    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/drawer_menu">
        
    </com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>

标签: androidxmlandroid-layoutdrawerlayoutandroid-nestedscrollview

解决方案


将 NestedScrollView 高度设置为 match_parent


推荐阅读