6

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 has method resetToTop() which clears all cached stuff and draws everything from scratch.

There are some workarounds:

  • Call layoutManager.onDetachedFromWindow(recyclerView, null) after clearing an adapter
  • Set new layout manager which is bad

add 20 items to adapter scroll a bit remove items, notifyChanges, add 20 items

Alex
  • 1,396
  • 1
  • 13
  • 22

1 Answers1

3

There are some workarounds:

  • Call layoutManager.onDetachedFromWindow(recyclerView, null) after clearing an adapter
  • Set new layout manager which is bad
Alex
  • 1,396
  • 1
  • 13
  • 22
  • Well, this is an unusual question, yet it doesn't look like a question but the information given just solved the case, Call layoutManager.onDetachedFromWindow(recyclerView, null) after clearing an adapter Thank you, now offset problem is disappeared – Yunus Yurtturk Feb 22 '16 at 19:49