I have a LazyColumn that looks like this:
LazyColumn (
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
items(bookList) { book ->
InProgressBookItem(book = book)
}
}
How can I add a line between each item in the list, similar to using an item decoration on the old RecyclerView?
We can make the Column scrollable by using the verticalScroll() modifier.
Recomposition is when Jetpack Compose re-executes the composables that may have changed in response to state changes, and then updates the Composition to reflect any changes. A Composition can only be produced by an initial composition and updated by recomposition.
A side-effect in Compose is a change to the state of the app that happens outside the scope of a composable function. For example, opening a new screen when the user taps on a button, or showing a message when the app doesn't have Internet connection.
Jetpack Compose is a modern declarative UI Toolkit for Android. Compose makes it easier to write and maintain your app UI by providing a declarative API that allows you to render your app UI without imperatively mutating frontend views.
Currently there is no built–in way to add dividers. However, you can just add a Divider
in the LazyListScope
.
Something like:
LazyColumn(
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
items(itemsList){
Text("Item at $it")
Divider(color = Color.Black)
}
}
If you do not want the last item to be followed by a Divider
, you can add dividers to items according to their indices:
LazyColumn(
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
itemsIndexed(itemsList) { index, item ->
Text("Item at index $index is $item")
if (index < itemsList.lastIndex)
Divider(color = Color.Black, thickness = 1.dp)
}
}
Simple:
LazyColumn (
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
items(bookList) { book ->
InProgressBookItem(book = book)
Divider(color = Color.Black, thickness = 1.dp)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With