![](/img/trans.png)
[英]Jetpack Compose - how to make SwipeToDismiss work on LazyRow?
[英]How do I start a lazyRow in the last index on Jetpack Compose?
啟動應用程序時,如何將lazyRow go 設置為最后一個索引?
@Composable
fun MessageList(messages: List<Message>) {
val listState = rememberLazyListState()
// Remember a CoroutineScope to be able to launch
val coroutineScope = rememberCoroutineScope()
LazyColumn(state = listState) {
// ...
}
ScrollToTopButton(
onClick = {
coroutineScope.launch {
// Animate scroll to the first item
listState.animateScrollToItem(index = lastIndex)
}
}
)
}
請在此處參考文檔以獲取更多信息
你可以為 LazyRow 做同樣的事情
您可以使用方法animateScrollToItem
:
就像是:
val itemsList = //... your list
val listState = rememberLazyListState()
// Remember a CoroutineScope to be able to launch
val coroutineScope = rememberCoroutineScope()
LazyColumn(state = listState) {
items(itemsList){
Text( "Item $it" )
}
}
要自動啟動,您可以使用:
DisposableEffect(Unit) {
coroutineScope.launch {
listState.animateScrollToItem(index = itemsList.size-1)
}
onDispose { }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.