在 JetpackCompose 中,我们可以使用LazyColumnFor
as RecyclerView
。
在RecyclerView
中,要在项目之间有适当的边距/填充,我们需要使用ItemDecoration
,根据本文
像下面
class MarginItemDecoration(private val spaceHeight: Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View,
parent: RecyclerView, state: RecyclerView.State) {
with(outRect) {
if (parent.getChildAdapterPosition(view) == 0) {
top = spaceHeight
}
left = spaceHeight
right = spaceHeight
bottom = spaceHeight
}
}
}
对于 JetpackCompose LazyColumnFor
,相当于ItemDecoration
什么?