scrollToItem() 函数,立即"捕捉滚动位置,animateScrollToItem() 使用动画滚动类似于:val listState = rememberLazyListState()//记住一个 CoroutineScope 才能启动val coroutineScope = rememberCoroutineScope()LazyColumn(state = listState) {//...}按钮 (onClick = {coroutineScope.launch {//动画滚动到第 10 项listState.animateScrollToItem(index = 10)}}){文本(点击")}Is there any way to programmatically scroll LazyColumn to some item in the list? I thought that it can be done by hoisting the LazyColumn argument state: LazyListState = rememberLazyListState() but I have no idea how I can change this state e.g. on Button click. 解决方案 With 1.0.x LazyListState supports the scroll position viathe scrollToItem() function, which ‘immediately’ snaps the scroll position,animateScrollToItem() which scrolls using an animationSomething like:val listState = rememberLazyListState()// Remember a CoroutineScope to be able to launchval coroutineScope = rememberCoroutineScope()LazyColumn(state = listState) { // ...}Button ( onClick = { coroutineScope.launch { // Animate scroll to the 10th item listState.animateScrollToItem(index = 10) } }){ Text("Click")} 这篇关于Jetpack Compose LazyColumn 以编程方式滚动到 Item的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-16 04:40