https://kotlinlang.org logo
#compose
Title
# compose
f

Fudge

07/16/2020, 12:15 PM
How can I place a component under a
LazyColumnItems
? I have no problem placing one above it, e.g.
Copy code
Column {
            Text("top")
            LazyColumnItems(items = listOf("1","2","3")) {
                Text(it)
            }
        }
But if I try to place it below the
bottom
text doesn't appear.
Copy code
Column {
            LazyColumnItems(items = listOf("1","2","3")) {
                Text(it)
            }
            Text("bottom")
        }
(In my case I also want to attach
bottom
to the bottom of the column so I would add
fillMaxHeight().wrapContentHeight(Alignment.Bottom)
as well)
m

matvei

07/16/2020, 12:26 PM
LazyColumnItems
and
LazyRowItems
are yet to support wrap content, now they always fill
😢 1
t

Timo Drick

07/16/2020, 12:52 PM
Do you really want this? Noramlly you use LazyColumnItems when you expect a large number of items (>5) and this will fill the complete screen and than the bottom text is not visible anyways. So maybe you want an other layout? Maybe set the height to Modifier.weight(1f) for the LazyColumnItems element?
Copy code
Column {
            LazyColumnItems(modifier = Modifier.weight(1f), items = listOf("1","2","3")) {
                Text(it)
            }
            Text("bottom")
        }
f

Fudge

07/16/2020, 1:01 PM
I want the LazyColumnItems to end at the bottom element
using Modifier.weight() made the list disappear 😢
t

Timo Drick

07/16/2020, 1:05 PM
With my suggestion it will look exactly like this. But when you have not enough items in the list to fill the view there will be a gap between the last element in list and the bottom element.
f

Fudge

07/16/2020, 1:05 PM
yes that is good
t

Timo Drick

07/16/2020, 1:05 PM
weight(1f)
f

Fudge

07/16/2020, 1:05 PM
let me try to do it exactly like you showed, sec
yes that seems to work, I need to figure out why it doesn't work in my app then
t

Timo Drick

07/16/2020, 1:07 PM
This weight(1f) is the same like in the legacy (LinearLayout). So it will fill the rest of available space with the list.
f

Fudge

07/16/2020, 1:11 PM
Nice it works well now, thank you!
👍 1
2 Views