Fixed
Status Update
Comments
[Deleted User] <[Deleted User]> #2
There is a stickyHeader
method, like that stickyFooter
will be awsome
ma...@google.com <ma...@google.com>
an...@google.com <an...@google.com> #3
Thanks for the request. Theoretical stickyFooter will not behave as you want, what sticky does is just keeps it on screen during the scrolling. But good news are we already have an api which can help you. There is a verticalArrangement param on LazyColumn which controls how the items are laid out when there are more space than needed to fill all the elements. Something like this should work:
LazyColumn(verticalArrangement = remember {
object : Arrangement.Vertical {
override fun Density.arrange(
totalSize: Int,
sizes: IntArray,
outPositions: IntArray
) {
var currentOffset = 0
sizes.forEachIndexed { index, size ->
if (index == sizes.lastIndex) {
outPositions[index] = totalSize - size
} else {
outPositions[index] = currentOffset
currentOffset += size
}
}
}
}
})
bl...@gmail.com <bl...@gmail.com> #4
The solution above does not do anything, the last item of the lazy column is still just another item, it's not aligned to the bottom. Please provide a proper fix.
an...@google.com <an...@google.com> #5
I think you need to also put Modifier.fillMaxHeight() on LazyColumn, as without that the height of LazyColumn will be just wrapping the size of items
bl...@gmail.com <bl...@gmail.com> #6
I did and the height is correct, I can see in the inspector that the LazyColumn is the size of the screen and still the last element is not at the bottom. Compose 1.2.0
st...@gmail.com <st...@gmail.com> #7
I did exactly as #3 mentions and it worked as expected
tr...@gmail.com <tr...@gmail.com> #8
This seems to work for me. Is this a working solution or are there performance issues I am missing?
Box(modifier = Modifier.fillMaxSize()){
LazyColumn(){
stickyHeader {
Text("BEHOLD THE STICKY HEADER!", fontSize = 30.sp)
}
items(35) { index ->
Text(text = "Item: $index",fontSize = 30.sp)
}
}
Column(
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter).background(Color.Red),
){
Text("It is I, the Sticky Footer", fontSize = 30.sp)
}
}
Description
Possibility to add a `LazyColumn` item that is aligned to its bottom.
Use Case:
In a `LazyColumn`, I’d like the last item to behave differently depending on the total size of the content. When the content of the `LazyColumn` is smaller than the `LazyColumn` itself, the last item should be aligned to the bottom of it. Otherwise, it should behave normally.