sindrenm
01/23/2025, 1:00 PMephemient
01/23/2025, 1:17 PMEduardo Andrade
01/23/2025, 1:56 PMSpaceBetween
arrangement and then wrap each column in a Box
with a weight
modifier. This would get you your desired alignment, regardless of font and text size on the first column.
Very sloppy code to give you a general idea of what I mean, as well as a screenshot of the result.
Hope this helps!
LazyColumn {
val items = listOf(
Triple<String, String, String>("test", "testwsets", "test"),
Triple<String, String, String>("t", "testwsets", "test"),
Triple<String, String, String>("123123123", "testwsets", "test")
)
items(items) { item ->
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween
) {
Box(modifier = Modifier.weight(1f)) {
Column {
Text(
text = item.first
)
Text(
text = item.first
)
}
}
Box(
modifier = Modifier.weight(2f)
) {
Column() {
Text(
text = item.second
)
Text(
text = item.second
)
Text(
text = item.second
)
}
}
Box(
modifier = Modifier.weight(1f),
contentAlignment = Alignment.CenterEnd
) {
Button(
onClick = { /* Booking logic */ },
modifier = Modifier.width(100.dp)
) {
Text("Book")
}
}
}
}
}
ephemient
01/23/2025, 1:57 PMEduardo Andrade
01/23/2025, 2:01 PMWinson Chiu
01/23/2025, 3:35 PMStylianos Gakis
01/23/2025, 4:29 PMRow {
Box() {
TimeAndDurationColumn("5:00 PM", "45 min")
for (otherEntry in allEntries) {
TimeAndDurationColumn(otherEntry, Modifier.withoutPlacement())
}
}
Column {
IndoorLifting(); SATSetc...
}
}
So you put them all one over another in a box, but you ensure that all the ones that are not for the current item are not placed at all, only measured. That way the outer box is always measured to be as big as the biggest one of them would be.
This also ensured first frame correctness since there is no remembering and setting any mutableState.
p.s: .withoutPlacement is this:
fun Modifier.withoutPlacement(): Modifier = this.layout { measurable, constraints ->
val boxPlaceable = measurable.measure(constraints)
layout(width = boxPlaceable.width, height = boxPlaceable.height) {}
}
ephemient
01/24/2025, 8:25 AMsindrenm
01/24/2025, 9:06 AMsindrenm
01/24/2025, 9:06 AMsindrenm
01/24/2025, 9:06 AMsindrenm
01/24/2025, 9:06 AMTextMeasurer
approach is also one that I considered initially, but I quickly discarded it as being too expensive. On second thought, though, it's probably the right approach here. We won't have too many items in this list, either, and the ability to have first-frame correctness weighs in a lot here for me.sindrenm
01/24/2025, 9:06 AMDmitry Strekha
01/24/2025, 10:37 AMRow {
Column(Modifier.width(IntrinsicSize.Max)) {
// time
}
Column(Modifier.weight(1f)) {
// content
}
}
Stylianos Gakis
01/24/2025, 10:56 AMDmitry Strekha
01/24/2025, 11:10 AM