我在工具栏中有一个带有过滤搜索的recyclelerview。当我开始搜索时,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项目的单击操作能够获取搜索到的信息。但这个列表永远不会滚动。我已经尝试了许多方法从相关问题中获取提示(添加各种类型的滚动布局,在各个位置调用与滚动相关的属性等等,所有这些都在协调器布局中)但行为保持不变。我必须做一些非常愚蠢的事情才能杀死这种基本行为。
答案 0 :(得分:1)
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中删除。
答案 1 :(得分:1)
尝试移动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>