这个是好的,加上 key 来保留滚动位置
@
Preview@
OptIn(ExperimentalFoundationApi::class)
@
Composablefun VerticalPagerWithLazyColumn(
modifier: Modifier = Modifier
) {
val pagerState = rememberPagerState(
pageCount = {
5
}
)
VerticalPager(
state = pagerState,
key = { it },
modifier = modifier.fillMaxSize()
) { page ->
Box {
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.fillMaxSize()
) {
for (i in 0..20) {
Text(
"Item $i on page $page",
modifier = Modifier.padding(30.dp)
)
}
}
Text(
"Page $page", modifier = Modifier
.padding(16.dp)
.align(Alignment.Center)
)
}
}
}