https://kotlinlang.org logo
Title
l

lesincs

11/25/2021, 12:03 AM
How to make
item
of
LazyColumn
fill the reset of the height? See thread.
LazyColumn(modifier = Modifier.fillMaxSize()) {
    item {
        Spacer(
            modifier = Modifier
                .background(Color.Red)
                .fillMaxWidth()
                .height(80.dp)
        )
    }

    item {
        Spacer(
            modifier = Modifier
                .background(Color.Green)
                .fillParentMaxSize()
        )
    }
}
In the code below, I want to make the second
item
with green background fill the reset height of the
LazyColumn.
I tried use
Modifier.fillMaxSize()
, but it didn’t work in
LazyColumn
, then I tried
Modifier.fillParentMaxSize
, which is only in
LazyItemScope
, but it did not work either, the effect is the second item’s height will be as same as the whole
LazyColumn
. So I want to know is there are some elegant ways to do this? I tried some tricky way like use the
Modifier.onSizeChanged
, and did some calculation, it works, but the code is terrible. And Why I used a
LazyColumn
instead of a normal
Column
is that there are some hidden logic, basically the second item is loading section which I want to centralize the loading indicator,so I need to it fill the rest height.
c

Csaba Kozák

11/25/2021, 9:23 AM
fillParentMaxSize()
has a
fraction
parameter, but i am afraid you have to calculate the size of the normal elements so your loader only takes the rest of the list height.
✔️ 1
a

Andrey Kulikov

11/26/2021, 10:02 PM
maybe to just not use LazyColumn when you don’t have enough elements? your content is not scrollable so you can just solve it with Column. and once you have real items to scroll switch to LazyColumn
👌 1