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