Search code examples
androidsearchandroid-recyclerviewandroid-coordinatorlayout

RecyclerView does not scroll while searching


I have a recyclerview assoicated with a filtered search in a toolbar. When I start the search, the number of items displayed by the recyclerview is far larger than the screen size. But when I try to scroll up by swiping to look at the elements off the screen, there no response. I thought RecyclerViews like ListViews always support scrolling. Any ideas why my RecyclerView is not scrolling?

Here is the coordinator layout for the tool bar, search, and recycler view that gets included in my main layout (I apologize for the formatting but the insert code widget does not work correctly):

<?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>

The main layout is as follows

<?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>

All other aspects appear to be okay. The list interactively responds to user input text and click actions on the recyclerview items are able to obtain the searched-for information. But this list never scrolls. I have tried numerous approaches taking hints from related issues (adding various types of scroll layouts, invoking scroll-related attributes in various places, etc. all within the coordinator layout) but the behavior remains unchanged. There must be something really stupid that I am doing to kill such a basic behavior.


Solution

  • Try moving the RecyclerView outside of the AppBarLayout as follows:

    <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>