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

Colton Idle

06/13/2022, 8:26 PM
I have this weird requirement where I have to give a Box the same height that is equal to the total height of the 1st and 2nd item of a LazyCol on top of the box.. The 1st and 2nd item in the list can change at any time or else I would just try to take the easy route and use some hardcoded height. How can I properly set a variable of
totalHeightOfFirstAndSecondItemInLazyCol
.
Copy code
Box {
Box(fillMaxWidth().height(totalHeightOfFirstAndSecondItemInLazyCol)
LazyColumn() { //all items are different sizes }
}
s

ste

06/13/2022, 8:40 PM
Copy code
lazyListState.layoutInfo.visibleItemsInfo.let { 
    it.getOrNull(0)?.size?.plus(it.getOrNull(1)?.size ?: 0) ?: 0
}
?
🧠 1
c

Colton Idle

06/13/2022, 8:55 PM
Ooh. TIL. I think that'll work. Ill give it a shot when im back by my computer
2 Views