【发布时间】:2018-09-16 06:16:13
【问题描述】:
我是 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