Compose Column 实现滚动


 // 我们用这个状态保存滚动位置
    val scrollState = rememberScrollState()
    Column(Modifier.verticalScroll(scrollState)) {
         。。。
    }
//滚动列表控件
 LazyColumn {
        items(100) { //注意这里不是repeat,
            Text("Item #$it", style = MaterialTheme.typography.subtitle1)
        }
    }
    val listSize = 100
    // 保存滚动状态
    val scrollState = rememberLazyListState()
    // 保存将执行动画滚动的协程范围
    val coroutineScope = rememberCoroutineScope()
    Column {
        Row {
            Button(onClick = {
                //回到顶部
                coroutineScope.launch {
                    scrollState.animateScrollToItem(0)
                }
            }) {
                Text("Scroll to the top")
            }
            Button(onClick = {
                //回到底部
                coroutineScope.launch {
                    scrollState.animateScrollToItem(listSize - 1)
                }
            }) {
                Text("Scroll to the end")
            }
        }
        LazyColumn(state = scrollState) {
            items(listSize) {
                ImageListItem(it)
            }
        }
    } 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM