本文介绍了Android StaggeredGridLayoutManager偏移错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

清除适配器并调用notifyDataSetChanged()时- StaggedGridLayoutManager 管理器在Span[]实例中仍然具有mCachedStart/End.因此,当您向适配器中添加新项目时,布局管理器会绘制具有偏移量的项目,这是一个巨大的问题.

When you clear your adapter and call notifyDataSetChanged() - StaggedGridLayoutManager manager still has mCachedStart/End in Span[] instances. So when you add new items to adapter - layout manager draws items with offset, and this is a huge problem.

EtsyStaggeredGridView 具有方法resetToTop(),该方法清除所有缓存的内容并从头开始绘制所有内容.

EtsyStaggeredGridView has method resetToTop() which clears all cached stuff and draws everything from scratch.

有一些解决方法:

  • 清除适配器后呼叫layoutManager.onDetachedFromWindow(recyclerView, null)
  • 设置布局管理器,该管理器不好
  • Call layoutManager.onDetachedFromWindow(recyclerView, null) after clearing an adapter
  • Set new layout manager which is bad

推荐答案

有一些解决方法:

  • 清除适配器后呼叫layoutManager.onDetachedFromWindow(recyclerView, null)
  • 设置布局管理器,该管理器不好
  • Call layoutManager.onDetachedFromWindow(recyclerView, null) after clearing an adapter
  • Set new layout manager which is bad

这篇关于Android StaggeredGridLayoutManager偏移错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:47