In JetpackCompose, we can use LazyColumnFor
as RecyclerView
.
In RecyclerView
, to have a proper margin/padding between items, we need to use ItemDecoration
, as per this article
Like below
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
}
}
}
For JetpackCompose LazyColumnFor
, what's the equivalent of ItemDecoration
?
I kind of workaround using
contentPadding
ofLazyColumnFor
for top, start and end padding, andSpacer
as the bottom padding for all items.This seems to get the result I needed, as the
contentPadding
can be scrolled together within theLazyColumnFor