1

我是安卓新手。有人可以帮助解决“奇怪的” StaggeredGridLayout 行为。附在下面的GIF:

first_example_StaggeredGridLayout_behavior.gif

second_example_StaggeredGridLayout_behavior.gif

我的回收站初始化代码:

 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)))

物品装饰类

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)

 }
}

我研究了很多资源,但都没有帮助解决我的问题。提前致谢。

4

1 回答 1

0

您是否尝试过使用 item Animator?

photoRecycler.setItemAnimator(null);

上面的代码将删除应用于回收器视图的默认动画器。

于 2018-04-06T09:24:24.693 回答