Trying to align text elements as shown in the image below:

How to do it in Jetpack Compose?
Normally I would use a Linear Layout with vertical orientation and TextViews with a rotation of 90. Wondering how to achieve this in compose.
compose_verion: 1.0.0-beta02
To rotate an element you can use Modifier.rotate() modifier
Column {
Text(text = "text", modifier = Modifier.rotate(-90f))
Text(text = "text", modifier = Modifier.rotate(-90f))
Text(text = "text", modifier = Modifier.rotate(-90f))
}
The solution with a custom modifier from How to show vertical text with proper size/layout in jetpack compose worked for me:
fun Modifier.vertical() = layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
layout(placeable.height, placeable.width) {
placeable.place(
x = -(placeable.width / 2 - placeable.height / 2),
y = -(placeable.height / 2 - placeable.width / 2)
)
}
}
Used as
Text(
modifier = Modifier.vertical().rotate(-90f),
text = "Vertical aligned element"
)
Credits to Sergei S's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With