Is there any layout like FlowRow but with the effo...
# compose
p
Is there any layout like FlowRow but with the effort to keep equal number of items in each row? For example if there are 6 items and all fit in one row then it will be one row, if only five items fit in one row then there will be 2 rows with 3 items in each. Current FlowRow implementation will have 2 rows with 5 and 1 items for second scenario. It needs to be calculated dynamicaly depending on screen width and children widths (no constant settings like maxItemsInEachRow).
m
I haven't seen anything, but you could always write your own custom layout for this. I think the complication is that you'd almost have to be using intrinsic sizes on all the children and finding the appropriate breaking point to achieve a balanced row width would be difficult without being able to re-order things.
s
Do you want them to visually align, or the number of them to match? If the first three are very wide and all together take up 99% of the width, and then the next 3 re tiny and all together take up only 20% of the screen, and then you have a seventh item, where you you want the seventh item to be?
p
All children are the same width for my case. Need just equal number per row.
s
It sounds trivial to build your own layout for this then. You need to measure them and divide the width of any one of them by the constraints.maxWidth and you'll right there know how many fit in each row. Do you wanted to also control then their alignment or do you want them to be attached to the left?
Start here https://developer.android.com/develop/ui/compose/layouts/custom#create-custom to get an idea if you've never done this before.
p
Got it. Will make own layout. Thanks! Need center alignment - will do offset as half of remain space.
👍 1