【问题标题】:ListView inside NavigationView not scrollingNavigationView 中的 ListView 不滚动
【发布时间】:2021-02-15 22:01:46
【问题描述】:

我一直试图让我的 NavigationView 可滚动 - 以便能够查看其中的所有项目。之前我使用菜单项来填充我的 NavigationView,但 NavigationView 没有滚动。在网上搜索了很多之后,使 NavigationView 可滚动的最流行的建议似乎是在 NavigationView 中使用 ListView。我试过了,但我的 NavigationView 仍然不滚动。

这是我的 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"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#1F262F"
        android:fitsSystemWindows="true"
        android:paddingTop="24dp"
        android:paddingBottom="0dp"
        app:itemIconTint="#FFFFFF"
        app:itemTextColor="#FFFFFF">

        <ListView
            android:id="@+id/navList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </com.google.android.material.navigation.NavigationView>

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

</androidx.drawerlayout.widget.DrawerLayout>

请提出一个解决方案,以便我可以向下滚动 NavigationView 以查看其中的所有项目。 请帮忙!

【问题讨论】:

    标签: android android-listview navigation-drawer


    【解决方案1】:

    您是否尝试过使用ScrollView

    另外,请注意ListView 现在有layout_width="wrap_content"

    <androidx.drawerlayout.widget.DrawerLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <com.google.android.material.navigation.NavigationView
            android:layout_width="wrap_content"
            android:layout_height="match_parent">
    
            <ScrollView
                android:layout_width="wrap_content"
                android:layout_height="match_parent" >
                
                <ListView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
    
            </ScrollView>            
        </com.google.android.material.navigation.NavigationView>
    </androidx.drawerlayout.widget.DrawerLayout>
    

    【讨论】:

    • 不幸的是它不起作用。如上所述,添加 Scrollview 会使 ListView 的所有项目消失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多