https://kotlinlang.org logo
a

allan.conda

10/05/2020, 1:57 PM
Does the LazyItemScope work like a Column? It seems so. Wondering if I need to wrap content of item in a Column or call
item{}
multiple times, since it says
Copy code
Adds a single item to the scope.
in the doc.
Copy code
LazyColumn {
   item { Text("Title") }
   item { Header() }
   items(items) { ... }
}
// or
LazyColumn {
   item {
      Text("Title)
      Header()
   } 
   items { ... } 
}
Ok seems I’m not able to align the items, so I probably have to wrap the components in a Column
a

Andrey Kulikov

10/05/2020, 2:09 PM
there is a
horizontalAlignment
alignment on
LazyColumn
. but it will be applied for all the items. if you define your title and the header with two separate item calls it will work a bit more efficient as once you will scroll up so the header is visible it will only need to create a Header for displaying, not both title and header. but you can put both of them in the same
item
, it also works
👍 1
a

allan.conda

10/05/2020, 2:16 PM
Ahhh, it makes sense having multiple item{} is actually more efficient than a single one. For some reason I thought that would be less performant. Thanks! For centering a single item though, not sure if I need to wrap it in a Column now to be able to align it. I’m just trying to center an inline CircularProgressIndicator
Copy code
item {
    Column(Modifier.fillMaxSize()) {
        CircularProgressIndicator(modifier = Modifier.align(Alignment.CenterHorizontally))
    }
}
I guess a Box would work as well
9 Views