'Is there a way to align a item on the bottom of a LazyColumn?
I'm trying to implement a list with a button on its bottom, like the following:
Since I don't know how many items I would have on the list, I'm using a LazyColumn. The button on the bottom, should only be placed there if the list doesn't fill the entire screen, if it does, the button should be moved down and be the last item on the list.
Moving the button inside the LazyColumn like this:
LazyColumn(...) {
items(items) { item -> ...}
item { Button() }
}
Gives the following:
I tried to add a Spacer with fillMaxHeight() modifier as an item between the two but it didn't change.
I also tried to add both the LazyColumn and the Button inside a column:
Column {
LazyColumn(
modifier = Modifier.weight(1f)
) {
items(items) { item -> ...}
}
Button()
}
But this only anchors the button on the bottom as if the Column was a LinearLayout.
Considering this, would it be possible to align one of the LazyColumn's items so it will always be on the bottom? Or, add some kind of space that fill the available area?
Solution 1:[1]
We can wrap the button and LazyColumn with Column like this and ues verticalArrangement SpaceBetween.
we also can replace SpaceBetween with SpaceAround
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.SpaceBetween
) {
LazyColumn(...) {
items(items) { item -> ... }
}
Button()
}
I hope that has helped you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


