https://kotlinlang.org logo
#compose
Title
# compose
l

Laura Oran

04/21/2020, 4:28 PM
Hello, anyone knows how to align center a Text with more than 1 line? With 1 line it is align center horizontally correctly, but with more no
This is my code:
Copy code
Column (modifier = Modifier.weight(1.0f, true)) {
    Image(
        image,
        Modifier
            .preferredSize(56.dp, 56.dp)
            .gravity(Alignment.CenterHorizontally)
    )
    Text(
        modifier = Modifier.gravity(Alignment.CenterHorizontally),
        text = itemTitle,
        style = MaterialTheme.typography.body1,
        maxLines = 3
    )
}
l

Louis Pullen-Freilich [G]

04/21/2020, 4:34 PM
Copy code
Text(
    text = itemTitle,
    style = MaterialTheme.typography.body1.copy(textAlign = TextAlign.Center)
)
Should work
gravity
is for layout alignment, it won't affect how the text inside the
Text
are aligned
l

Laura Oran

04/21/2020, 4:37 PM
wow thanks 😄
19 Views