【发布时间】:2021-06-26 06:50:57
【问题描述】:
当我将 RecyclerView 放入 NestedScrollView 时。 LayoutManager 和 RecyclerView 为 getChildCount() 和 getItemCount() 返回相同的值(它们总是相同,并且总是 ArrayList/MutableList 的最大值)。
我在 RecyclerView 的自定义适配器中添加了一个大型数据集。假设它是 400 个图像缩略图。 getItemCount() 应该返回 400,而 getChildCount() 应该只返回大约 20 个 RecyclerView 可以放在屏幕上的图像缩略图。
当我在 NestedScrollView 下使用 RecyclerView 时,getChildCount() 总是返回 400。我认为我的 RecyclerView 并没有像预期的那样回收视图,而且我实际上一次显示了 400 个缩略图,而不是 20 个。
现在,我知道我应该只使用 RecyclerView 本身。最有可能的是,移除 NestedScrollView 将使 RecyclerView 以它应该的方式工作。但我需要实现折叠工具栏,这通常使用带有 CoordinatorLayout 的 NestedScrollView 来完成。
是否有任何解决方法可以让 RecyclerView 带有折叠工具栏?
我的实现类似于this。
【问题讨论】:
标签: java android kotlin android-recyclerview android-coordinatorlayout