Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android StaggeredGridLayoutManager offset bug

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

like image 297
Alex Avatar asked Oct 14 '15 13:10

Alex


1 Answers

There are some workarounds:

  • Call layoutManager.onDetachedFromWindow(recyclerView, null) after clearing an adapter
  • Set new layout manager which is bad
like image 193
Alex Avatar answered Oct 21 '22 05:10

Alex