In LazyColumn, we can implement a custom arrangement that pushes the footer to the bottom of list when there are many items and keeps it fixed at the bottom of viewport when there are few items. The code like this:
object TopWithFooter : Arrangement.Vertical {
override fun Density.arrange(
totalSize: Int,
sizes: IntArray,
outPositions: IntArray
) {
var y = 0
sizes.forEachIndexed { index, size ->
outPositions[index] = y
y += size
}
if (y < totalSize) {
val lastIndex = outPositions.lastIndex
outPositions[lastIndex] = totalSize - sizes.last()
}
}
}
However, when I tried to apply a similar approach in LazyVerticalGrid, it didn’t work. I also tried debugging and noticed that the arrange()
method isn’t being called at all.
Is there a reason why custom arrangements don’t work in LazyVerticalGrid, or am I missing something? How can I achieve the same effect in a LazyVerticalGrid?