guys can you help at rotating text in compose? Im ...
# compose
g
guys can you help at rotating text in compose? Im using .rotate(90f) but for some reason text has paddings on the sides
here is the code
Copy code
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            VerticaltextTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Row(modifier = Modifier.padding(innerPadding)) {
                        Text(
                            text = "Hello Android! aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                            modifier = Modifier.rotate(90f).border(1.dp, Color.Gray)
                        )
                        Box(Modifier.fillMaxWidth().height(90.dp).background(Color.Gray))
                    }
                }
            }
        }
    }
}
s
This has nothing to do with the text being flipped right? The extra top-bottom padding is added there as spacing for taller characters etc
This article https://medium.com/androiddevelopers/fixing-font-padding-in-compose-text-768cd232425b may be interesting to you. Perhaps there's some API to try to trim those extra spacings as much as possible
g
there must be some missunderstanding. Text is not flipped, it is rotated, but the square next to it does not take full space. Font padding wont fix this,
s
Right, you're only rotating on the graphicsLayer right? That only rotates the way it's rendered, not the way it's laid out
g
so any way to rotate it fully?
s
I can't say I am aware of a way to do that. Could you try and draw your text on a Canvas instead?
g
Tried it but... failed. It took too much time and progress was like zero so I gave up