Alex Styl
01/15/2025, 7:23 AMFlowRow(Modifier.fillMaxSize()) {
Box(
Modifier
.background(Color.Red)
.aspectRatio(1f)
.weight(1f)
)
}
Alex Styl
01/15/2025, 7:23 AMAlex Styl
01/15/2025, 7:38 AMweight()
. Doesn't say if it is only scaled down though but maybe it works as intended.
In a FlowColumn, when a weight is applied to an item, the item is scaled based on the number of weighted items that fall on the column it was placed in.
EDIT: On a second though, how does it choose the specific height though. w/o the aspectRatio() the Box would be 0.dp tallAlex Styl
01/15/2025, 7:47 AMAlex Styl
01/15/2025, 7:53 AMLukas Anda
01/16/2025, 10:17 AMAlex Styl
01/18/2025, 4:51 AMLukas Anda
01/19/2025, 10:06 AMAlex Styl
01/19/2025, 6:49 PMAlex Styl
01/19/2025, 6:50 PMLukas Anda
01/19/2025, 6:56 PMAlex Styl
01/20/2025, 4:23 AM<div>
<h2>I am some text outside of flex wrap</h2>
<div class="flex flex-wrap">
<div class="w-1/2 h-32 bg-blue-500"></div>
<div class="w-1/3 h-24 bg-green-500"></div>
<div class="w-1/4 h-40 bg-red-500 "></div>
<div class="w-1/3 h-28 bg-yellow-500 "></div>
<div class="w-1/4 h-36 bg-purple-500 "></div>
<div class="w-1/2 h-32 bg-blue-500 "></div>
<div class="w-1/3 h-24 bg-green-500 "></div>
<div class="w-1/4 h-40 bg-red-500 "></div>
<div class="w-1/3 h-28 bg-yellow-500 "></div>
<div class="w-1/4 h-36 bg-purple-500 "></div>
<div class="w-1/2 h-32 bg-blue-500 "></div>
<div class="w-1/3 h-24 bg-green-500 "></div>
<div class="w-1/4 h-40 bg-red-500 "></div>
<div class="w-1/3 h-28 bg-yellow-500 "></div>
<div class="w-1/4 h-36 bg-purple-500 "></div>
</div>
<h2>I am some text outside of flex wrap</h2>
</div>
Lukas Anda
01/20/2025, 9:12 AM@Composable
fun WeightedFlewRow(modifier: Modifier = Modifier) {
Column {
Text("Text before")
FlowRow(modifier = Modifier.fillMaxWidth()) {
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 2f)
.background(Color.Blue))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 3f)
.background(Color.Green))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 4f)
.background(Color.Red))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 3f)
.background(Color.Yellow))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 4f)
.background(Color.Magenta))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 2f)
.background(Color.Blue))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 3f)
.background(Color.Green))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 4f)
.background(Color.Red))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 3f)
.background(Color.Yellow))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 4f)
.background(Color.Magenta))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 2f)
.background(Color.Blue))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 3f)
.background(Color.Green))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 4f)
.background(Color.Red))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 3f)
.background(Color.Yellow))
Box(modifier = Modifier
.height(40.dp)
.fillMaxWidth(1 / 4f)
.background(Color.Magenta))
}
Text("Text after")
}
}
which will look like this:Alex Styl
01/20/2025, 9:25 AMLukas Anda
01/20/2025, 9:31 AMAlex Styl
01/20/2025, 9:36 AMAlex Styl
01/20/2025, 9:36 AMLukas Anda
01/20/2025, 10:03 AMBox(modifier = Modifier
.fillMaxWidth(1 / 2f)
.aspectRatio(8f, true)
.background(Color.Blue))
Hopefully that will achieve your expected resultAlex Styl
01/20/2025, 10:21 AMAlex Styl
01/20/2025, 10:22 AMLukas Anda
01/20/2025, 10:44 AM