-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
RecyclerView卡頓的大招优化 #7
Comments
太狠了 ,这招 |
确实挺狠的,会有什么隐患吗 |
可以,空间换性能。学到了 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RecyclerView的卡顿问题归根结底是滑动的卡顿,有一个场景是ViewHolder在滑动过程中创建ViewHolder导致的卡顿,那么问题来了,是否可以在CPU空闲的时候我们给RecyclerViewPool预制一些ViewHolder,这样在滑动过程中只会调用bind方法,而不会调用create方法。
`//需要提前缓存ViewHolder,解决滑动卡顿问题,骚操作
MessageQueue.IdleHandler idleHandler = new MessageQueue.IdleHandler() {
@OverRide
public boolean queueIdle() {
new Thread(new Runnable() {
@OverRide
public void run() {
for (int i = 0; i < 10; i++) {
final RecyclerView.ViewHolder viewHolder = mController.getAdapter().createViewHolder(mRecyclerView, PicRecoveryBaseModel.TYPE_ITEM);
mRecyclerView.post(new Runnable() {
@OverRide
public void run() {
mRecyclerView.getRecycledViewPool().putRecycledView(viewHolder);
}
});
The text was updated successfully, but these errors were encountered: