Hi all. With `LazyVerticalStaggeredGrids` , is the...
# compose
x
Hi all. With
LazyVerticalStaggeredGrids
, is there a way to dynamically add padding in order to indent only certain items in appropriate positions? Code in 🧵
Just realised its not super obvious with the screenshot above, but there's two levels of indentation i want to achieve
MyListView.kt
j
You can do a custom arrangement 🙂 If check in source code for Arrangement.spacedBy, they do like this to put space:
Copy code
internal fun placeSpaceAround(
        totalSize: Int,
        size: IntArray,
        outPosition: IntArray,
        reverseInput: Boolean
    ) {
        val consumedSize = size.fold(0) { a, b -> a + b }
        val gapSize = if (size.isNotEmpty()) {
            (totalSize - consumedSize).toFloat() / size.size
        } else {
            0f
        }
        var current = gapSize / 2
        size.forEachIndexed(reverseInput) { index, it ->
            outPosition[index] = current.roundToInt()
            current += it.toFloat() + gapSize
        }
    }
👀 1
You can implement Horisontal and Vertical Arrangements in one class btw, by implement both interfaces 🙂