Sye*_*han 11 android android-recyclerview epoxy android-jetpack-compose android-jetpack-compose-list
在具有水平 LinearLayout 的 EpoxyRecyclerView 中,有一个“对齐中心”功能,其工作原理如下:如果我以良好的速度滚动列表,它会继续滚动,直到速度减慢并以项目位于中心为止。如果我缓慢滚动并抬起手指,那么下一个项目就会跨越/移动到屏幕中心。您必须了解一件事,这不是寻呼机。寻呼机仅自动捕捉下一个项目。但我不能像自由滚动一样滚动......
你可以看看这个 gif 作为例子
因此,我正在 Jetpack Compose 中寻找此类捕捉功能。这可能吗?如果是,如何实现这一目标?
您也可以使用这个库https://github.com/chrisbanes/snapper
https://chrisbanes.github.io/snapper/
val lazyListState = RememberLazyListState()
LazyRow(
state = lazyListState,
flingBehavior = rememberSnapperFlingBehavior(lazyListState),
) {
// content
}
Run Code Online (Sandbox Code Playgroud)
从 compose 开始,1.3.0您可以使用FlingBehavior将项目捕捉到给定位置的方法:
val state = rememberLazyListState()
LazyRow(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically,
state = state,
flingBehavior = rememberSnapFlingBehavior(lazyListState = state)
) {
//item content
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7428 次 |
| 最近记录: |