📌참고자료
📌참고자료
LazyListState
/LazyGridState
rememberLazyListState
/rememberLazyGridState
GridCells
LazyVerticalGrid(
columns = object: GridCells{
override fun Density.calculateCrossAxisCellSizes(
availableSize: Int,
spacing: Int
): List<Int>{
// return value: list containing the calculated column widths
// number of columns = length of the returned list
...
}
}
)
Don't use 0-pixel sized items
-> set default sizing to items
(item size should ideally be the same before & after loading the content)
Avoid nesting scrollable children without a predefined size inside another same-direction scrollable parent
-> wrap all the composables inside one parent lazy column
lazyColumn{
item{
Header()
}
items(data){item ->
Item(item)
}
item{
Footer()
}
}
scrollToItem
, animateScrollToItem
object TopWithFooter: Arrangement.Vertical{
override fun Density.arrange(
totalSize:Int, //size of viewport
sizes: IntArray, //sizes of items
outPositions: IntArray //positions of items
){
//화면 최상단부터 아이템 배치
var y = 0
sizes.forEachIndexed{index, size ->
outPositions[index] = y
y += size
}
//아이템 목록 길이가 화면 길이보다 짧다면
//마지막 아이템은 화면 최하단에 배치
if(y < totalSize){
val lastIndex = outPositions.lastIndex
outPositions[lastIndex] = totalSize - sizes.last()
}
}
}