我是安卓新手。有人可以帮助解决“奇怪的” 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)
}
}
我研究了很多资源,但都没有帮助解决我的问题。提前致谢。