交错网格布局行为问题

问题描述 投票:0回答:1

我是Android的新手。有人可以帮助“奇怪的”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)))

ItemDecoration类

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)

 }
}

我研究过很多来源,但都没有对我的问题有所帮助。提前致谢。

android android-recyclerview recyclerview-layout staggeredgridlayout staggeredgridlayoutmanager
1个回答
0
投票

你尝试过使用Animator项吗?

photoRecycler.setItemAnimator(null);

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

© www.soinside.com 2019 - 2024. All rights reserved.