Is there an `Arrangement` that gives each item the...
# compose
a
Is there an
Arrangement
that gives each item the same amount of “room” and then aligns within that room. Like if I put each item in a box of the same weight and aligned within the box?
a
Do you mean
Arrangement.SpaceEvenly
?
a
Unfortunately no.
SpaceEvenly
creates even spaces between the items, which is not the same.
r
Arrangement.spacedBy(dp, Alignment)
c
Arrangement
doesn’t affect the measurement of items, only placement.
a
I understand that. Anyway, there doesn’t seem to be an arrangement like I want, so I wrote my own.
Copy code
private fun placeEqually(
    totalSize: Int,
    size: IntArray,
    outPosition: IntArray,
    reverseInput: Boolean
) {
    val itemRoom = totalSize / size.size
    var current = 0
    size.forEachIndexed(reverseInput) { index, it ->
        outPosition[index] = current + (itemRoom - it)/2
        current += itemRoom
    }
}
for centered alignment anyway
c
Ah I misread and thought this was another ‘have all items match the max size item’ 🤦‍♂️
Your code looks good. Could even pass in an alignment and use that to affect the item float
a
The problem with all the existing arrangements is that when the size of one of the items changes, they all move around. So it doesn’t work if I want to display a row of numbers that are changing.
c
The movement isn’t necessarily a problem if you use
animateContentSize
a
It is in my app 🙂
c
Fair enough. At least
Arrangement
exists and is easy to use for custom behavior
a
Could be slightly easier if
IntArray.forEachIndexed(reversed: Boolean, action: (Int, Int) -> Unit)
wasn’t private