Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019-11-05:谈谈RecyclerView的缓存机制? #181

Open
MoJieBlog opened this issue Nov 5, 2019 · 4 comments
Open

2019-11-05:谈谈RecyclerView的缓存机制? #181

MoJieBlog opened this issue Nov 5, 2019 · 4 comments

Comments

@MoJieBlog
Copy link
Collaborator

  • 二级缓存。
  • Scrap做了什么?
  • Recycler做了什么?
  • 如何复用?
@darrenjh
Copy link

listview是2级缓存
Active View,Scrap view
RecyclerView的缓存分为四级:Scrap,Cache,ViewCacheExtension,RecycledViewPool
这里有篇文章,解释的很详细http://www.360doc.com/content/19/0712/11/36367108_848240455.shtml

@manondidi
Copy link

你说二级缓存,其实recyclerView缓存细分不止二级.
我来说说我的看法
scrap viewCache recyclerPool

scrap 是当前展示的缓存, 在onlayout时候 缓存
viewCache 是屏幕外看不见的缓存, 可以吧viewCache设置大点,空间换时间 避免段距离内快速滑动卡顿
以上两种缓存是不走 createView和 onbind
recyclerPool 比较特殊他是会走 onbind的,他可以被多个recyclerView共享内部的item,实际用途是:多个recyclerView之间共享item,应用在 垂直recyclerView 内嵌水平recyclerView,或者viewpager中多个recyclerView 网易新闻首页

@mlinqirong
Copy link

mlinqirong commented Dec 21, 2021

RecyclerView的缓存机制有四层
1,mChangedScrap和mAttachedScrap
用来缓存屏幕内的ViewHolder
2,mCachedViews(size=2先进先出)
用来缓存移除屏幕外的ViewHolder 默认size=2 如果再添加时size>2 取出第0个存入mRecyclerPool 然后移除mCachedViews第0个 再添加新的ViewHolder
3,mViewCacheExtension
自定义缓存 提供开发者 自定义缓存
4,mRecyclerPool(size=5)
recyclerPool 缓存池 以type分块每块size=5 mCachedViews空间满时添加到mRecyclerPool缓存 mCachedViews找不到ViewHoler时去mRecyclerPool获取

@CKTim
Copy link

CKTim commented Feb 7, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants