Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose: LazyColumn align each item separately [duplicate]

I want to align each item in a column one by one. I believe it's possible in simple Column using align operator like that:

Column {
   Text(text = "First", modifier = Modifier.align(Alignment.Start))
   Text(text = "Second", modifier = Modifier.align(Alignment.End))
   Text(text = "Third", modifier = Modifier.align(Alignment.Start))
}

However I cannot find align operator for LazyColumn in appropriate scopes. How to do it in LazyColumn? I'm not interested in horizontalAlignment as it applies to all items.

like image 375
adek111 Avatar asked Mar 11 '26 17:03

adek111


1 Answers

You can wrap each item in a Box and then apply alignment within the Box.

Box(modifier = Modifier.fillMaxWidth()) {
    Text(text = "First", modifier = Modifier.align(Alignment.TopCenter))
}

Another solution is to use 2 modifier attributes:

Text(
    text = "Your text here",
    modifier = Modifier
        .fillMaxWidth()
        .wrapContentWidth(align = Alignment.CenterHorizontally),
)
like image 66
Francesc Avatar answered Mar 14 '26 08:03

Francesc