RecyclerView 在搜索时不滚动

RecyclerView does not scroll while searching

我有一个 recyclerview 与工具栏中的过滤搜索相关联。当我开始搜索时,recyclerview 显示的项目数量远远大于屏幕尺寸。但是当我尝试通过滑动向上滚动以查看屏幕外的元素时,没有任何响应。我认为像 ListViews 这样的 RecyclerViews 总是支持滚动。知道为什么我的 RecyclerView 不滚动吗?

这是包含在我的主布局中的工具栏、搜索和回收器视图的协调器布局(对于格式我深表歉意,但插入代码小部件无法正常工作):

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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:fitsSystemWindows="true"                                                 
    tools:context="com.lampreynetworks.cpa.CPA_Activity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_search_id"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorToolbarBackground"
            android:theme="@style/AppThemeDark"
            app:contentInsetEnd="0dp"
            app:contentInsetStart="0dp">
        </android.support.v7.widget.Toolbar>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/card_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

主要布局如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/base_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fitsSystemWindows="true"
          tools:context="com.lampreynetworks.cpa.CPA_Activity"
          android:orientation="vertical">

<include
    android:id="@+id/toolbar_search"
    layout="@layout/toolbar_search_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<android.support.v4.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">

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

        <RelativeLayout
            android:id="@+id/borderLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:background="@drawable/text_view_border"
            android:orientation="vertical">

            <TextView
                android:id="@+id/text_connect_status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="6dp"
                android:text="some text"
                android:textColor="@color/orange"
                android:textStyle="bold"/>
        </RelativeLayout>

        <ListView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/borderLayout"
            android:layout_marginLeft="4dp"
            android:layout_marginStart="4dp"
            android:choiceMode="none"
            android:stackFromBottom="false">
        </ListView>

    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/nav_drawer_menu"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>

其他方面都还好。该列表以交互方式响应用户输入的文本,点击 recyclerview 项目上的操作可以获得搜索到的信息。但是这个列表永远不会滚动。我尝试了多种方法,从相关问题中获取提示(添加各种类型的滚动布局,在各个地方调用滚动相关的属性等,所有这些都在协调器布局中),但行为保持不变。一定是我在做一些非常愚蠢的事情来扼杀这种基本行为。

change recyclerview height to wrap_content.

<android.support.v7.widget.RecyclerView
            android:id="@+id/card_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

将你的 recyclerview 移出 AppBarLayout。

尝试将 RecyclerView 移动到 AppBarLayout 之外,如下所示:

<android.support.design.widget.CoordinatorLayout                                           
    android:layout_width="match_parent"                                                 
    android:layout_height="match_parent"                                                 
    android:fitsSystemWindows="true"                                                 
    tools:context="com.lampreynetworks.cpa.CPA_Activity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_search_id"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorToolbarBackground"
            android:theme="@style/AppThemeDark"
            app:contentInsetEnd="0dp"
            app:contentInsetStart="0dp">
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/card_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </android.support.design.widget.CoordinatorLayout>