https://kotlinlang.org logo
r

raenardev

07/16/2021, 5:25 PM
Is there a way to ensure some element center themselves by some text center?
Copy code
@Composable
fun TextVerticalCenter() {
    Row(verticalAlignment = CenterVertically, modifier = Modifier.background(Color.Black)) {
        Box(
            Modifier
                .size(8.dp)
                .background(Color.White)
        )
        Text(text = "Hello", color = Color.White, fontSize = 24.sp)
    }
}
If you look at screenshots, you can see that the box is slightly off center to the top (Even when all letters are same height). It is even more evident when looking at numbers. Sorry if i missed it while searching slack, but so far it seems that we have to wait for some way to turn off font padding for that: https://stackoverflow.com/questions/66126551/jetpack-compose-centering-text-without-font-padding
a
r

raenardev

07/19/2021, 10:52 AM
Yes, i was referring to this. My question was about other ways to achieve this (perhaps some text center baseline in future?) - do they exists, or we have to wait for now?
a

Albert Chang

07/19/2021, 10:54 AM
I think the issue explains it. There is no equivalent now.
1