[英]How to implement 'Snap to center' feature for lists in Jetpack Compose?
你也可以使用这个库https://github.com/chrisbanes/snapper
https://chrisbanes.github.io/snapper/
val lazyListState = rememberLazyListState()
LazyRow(
state = lazyListState,
flingBehavior = rememberSnapperFlingBehavior(lazyListState),
) {
// content
}
如果您使用 Compose 1.3,您可以在此处检查SnapFlingBehavior
你可以试试这个库: https : //github.com/aakarshrestha/compose-pager-snap-helper代码如下(使用LazyRow
列出项目)
ComposePagerSnapHelper(
width = 320.dp, //required
content = { listState -> //this param is provided by the method itself, add this param below.
LazyRow(
state = listState, //add listState param
) {
items(count = count) { item ->
//Put your Items Composable here
}
}
}
)
试试这个库https://github.com/chrisbanes/snapper
伴奏寻呼机最近已更新,现在实现了相同的行为。
从 compose 1.3.0
开始,您可以使用FlingBehavior
将项目捕捉到给定位置:
val state = rememberLazyListState()
LazyRow(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically,
state = state,
flingBehavior = rememberSnapFlingBehavior(lazyListState = state)
) {
//item content
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.