首页 > 解决方案 > 在recyclerview中显示gridview

问题描述

我正在尝试在 recyclerview 中显示网格视图问题是我的网格视图中的视图不能完全查看我需要显示具有 4 列和原始的网格视图,这取决于显示所有元素 这是什么我的应用程序现在正在显示,网格视图在这里是可滚动的,但我不希望它是可滚动的,因为我的父视图是回收器视图

[这里是一个关于 UI 应该是什么样子的示例][2] [2]:https://i.stack.imgur.com/IwJz1.jpg

这是抽屉布局的xml

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

    <include
        android:id="@+id/app_bar_home3"
        layout="@layout/activity_questions"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/grid_recycler" />
</androidx.drawerlayout.widget.DrawerLayout>

这是包含 recyclerview 的标题布局 (grid_recycler)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="350dp"
    android:layout_height="match_parent">
    <GridLayout
        android:id="@+id/grid_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:rowCount="3"
        android:columnCount="1"
        android:paddingTop="16dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:paddingBottom="16dp"
        android:background="@color/light_blue3">
    </GridLayout>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view_grid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </ScrollView>

</LinearLayout>

另外,如果您有关于打开抽屉的建议,请告诉我并使抽屉仅覆盖内屏幕(不是工具栏)。

标签: android-recyclerviewgridviewnavigation-drawerandroid-scrollable-tabs

解决方案


推荐阅读