Fudge
07/18/2020, 7:57 PMRow(horizontalArrangement = Arrangement.Center) {
Text("Center")
Text("Right", modifier = Modifier.fillMaxWidth().wrapContentWidth(Alignment.End))
}
Row(horizontalArrangement = Arrangement.Center) {
Text("Center")
Spacer(modifier = Modifier.weight(1f))
Text("Right")
}
As in both cases the Center
element will get attached to the left. The desired behavior is in this image:Mark Murphy
07/18/2020, 8:03 PMConstraintLayout
Fudge
07/18/2020, 8:06 PMMark Murphy
07/18/2020, 8:11 PMRow
, but your results are what I would expect from your code. In both cases, you are saying "I want the content to completely fill the row" via your whitespace rules. So, if the content fills the row, "Center"
will be on the left (in LTR, anyway). The Arrangement.Center
will be honored, more or less, but on the whole row content... and since that fills the row, it has no real effect.Fudge
07/18/2020, 8:16 PMStack
, I don't know if this is a good solution
Stack(Modifier.fillMaxWidth()) {
Text("Center", modifier = Modifier.gravity(Alignment.Center))
Text("Right", modifier = Modifier.gravity(Alignment.CenterEnd))
}
Mark Murphy
07/18/2020, 8:40 PMConstraintLayout
option would look like:
ConstraintLayout(Modifier.fillMaxWidth()) {
val (center, right) = createRefs()
Text("Center", modifier = Modifier.constrainAs(center) {
centerTo(parent)
})
Text("Right", modifier = Modifier.constrainAs(right) {
end.linkTo(parent.end)
})
}
Fudge
07/18/2020, 8:55 PMMark Murphy
07/18/2020, 8:55 PMAdam Powell
07/18/2020, 9:16 PMRow {
Spacer(Modifier.weight(1f))
Text("Hello")
Text("World", Modifier.weight(1f).wrapContentWidth(Alignment.End))
}