1

I`m new in Android. Could somebody help with "strange" StaggeredGridLayout behavior. GIFs attached below:

first_example_StaggeredGridLayout_behavior.gif

second_example_StaggeredGridLayout_behavior.gif

My recycler init code:

 val layoutManager = StaggeredGridLayoutManager(resources.getInteger(R.integer.span_value), StaggeredGridLayoutManager.VERTICAL)
 layoutManager.gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
 photoRecycler.adapter = adapterUnsplash
 photoRecycler.layoutManager = layoutManager
 photoRecycler.addItemDecoration(StaggeredItemDecoration(view.resources.getInteger(R.integer.column_spacing)))

ItemDecoration class

class StaggeredItemDecoration constructor(private var space: Int)
: RecyclerView.ItemDecoration() {

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {
       val halfSpacing = space / 2
       outRect.set(halfSpacing, halfSpacing, halfSpacing, halfSpacing)

 }
}

I've researched a lot of sources, but all didn`t help with my issue. Thanks in advance.

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57

1 Answers1

0

have you tried using item Animator?

photoRecycler.setItemAnimator(null);

The above piece of code will remove the default animator applied to the recycler view.