问题描述
我试图在以下代码行(其中mrecyclerView
是RecyclerView对象)中了解setRecycledViewPool方法与RecyclerView一起实际执行的操作:
I am trying to understand what the setRecycledViewPool method actually does along with the RecyclerView in the following line of code where mrecyclerView
is a RecyclerView object:
mrecyclerView.setRecycledViewPool(new RecyclerView.RecycledViewPool());
我阅读了Android文档链接我仍然不明白它的作用.有人可以向我解释其用途以及何时使用吗?
I read the Android documentation link and I still don't understand what it does clearly. Can someone explain to me its use and when to use it?
推荐答案
setRecycledViewPool(...)
可能会很有用.有关详细信息,请参见此博客文章.此处添加了相同链接的简短描述.
setRecycledViewPool(...)
can be useful when we have a nested RecyclerView. See this blog post for details. A short description of the same link is added here.
请考虑以下情况:嵌套的RecyclerView
和内部的RecycleView
具有相同的视图结构. RecycledViewPool
提供了一种无缝方式,可以在这些内部(嵌套)的RecyclerView
之间共享视图.
Consider a case where you have a nested RecyclerView
s and inner RecycleView
s share the same view structure. RecycledViewPool
provides a seemless way to share views between these inner (nested) RecyclerView
s.
下图中可以看到这种情况的示例:
An example of such case could be seen in the following image:
如您所见,两个列表的视图类型相同.
As you can see the types of views for both lists are same.
这篇关于RecyclerView中的setRecycledViewPool方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!