android - 使用搜索栏过滤时嵌套滚动视图中的回收器视图导致滞后
问题描述
我正在处理这个视图,顶部有一个标题,下面有一个搜索栏,然后是一个嵌套滚动视图,其中包含一个线性布局,进一步包含 2 个回收器视图。布局 xml 文件可以在下面找到。
我面临的问题是,当我通过搜索栏过滤回收站视图中的项目时,呈现过滤结果时存在明显的滞后。我已经将问题定位到嵌套滚动视图,因为当我摆脱这个(只有 2 个回收器视图)时,滞后的问题完全消失了。但是,当然,随着嵌套滚动视图的消失,我不能再同时滚动 2 个回收器视图。
现在,每个回收器视图都有 2 个适配器,每个适配器都实现了处理过滤逻辑的 Filterable 接口。此外,我有一个视图模型类和一个片段类。
如果这个问题不能轻易解决,那么我认为最后的办法是摆脱嵌套滚动视图,只有一个包含两个列表的回收器视图,并将适配器的数量减少到一个。这会使逻辑变得非常复杂,所以我希望有另一种解决方法。
请让我知道你们的想法。任何输入表示赞赏。
<androidx.constraintlayout.widget.ConstraintLayout 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/invite_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<include
android:id="@+id/header"
layout="@layout/component_bars_navigation_nav_sub"
android:layout_width="match_parent"
android:layout_height="@dimen/XXXL"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/search_bar"
layout="@layout/layout_component_bars_row_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/add_friend_header" />
<androidx.core.widget.NestedScrollView
android:id="@+id/invite_list_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:overScrollMode="always"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/search_bar">
<LinearLayout
android:id="@+id/invite_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/XXXXL"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="parent">
<include
android:id="@+id/label_1"
layout="@layout/layout_component_bars_row_label"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:paddingBottom="@dimen/S"
android:visibility="visible"
tools:itemCount="3"
tools:layout_editor_absoluteX="-50dp"
tools:listitem="@layout/components_1_item"
tools:visibility="visible" />
<include
android:id="@+id/label_2"
layout="@layout/layout_component_bars_row_label"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:paddingBottom="@dimen/S"
android:visibility="visible"
tools:itemCount="2"
tools:layout_editor_absoluteX="-50dp"
tools:listitem="@layout/components_2_item"
tools:visibility="visible" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
最后,我找到了解决这个问题的解决方案。我没有做多个回收视图,而是将它们组合成一个具有多种视图类型的视图。
如果人们仍然感到困惑,以下链接可能会有所帮助,因为它们帮助了我:)
推荐阅读
- ruby-on-rails - 关联的 has_many 上的回调不起作用
- r - 创建新方法时循环
- git - 使用 Git Kraken 时如何移动存储库?
- c# - 来自 JwtBearer 中间件的空声明
- amazon-web-services - 发布 .net core 3.0 AWS 无服务器应用程序时出错 - 项目名称“引导程序”不明确。”
- python - 如何在 spark udf 和 pandas 中的 python 2.7 中转换为字符串
- python - Python 是否有方便解析二进制格式的工具?
- asp.net-core-2.1 - .Net Core - 我如何从另一个 .net 核心类库(或项目)访问 .net 核心实体框架
- ios - iphone无法连接到查尔斯
- cakephp - cakePHP 为 SameSite 属性设置 Cookie。但我在代码中找不到它/追踪它