私は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)
}
}
私は多くのソースを調査しましたが、すべてが私の問題を解決しませんでした. 前もって感謝します。