【发布时间】:2022-09-30 19:10:38
【问题描述】:
在滚动后或在惰性列中点击(单击)后,我需要以编程方式滚动(以便捕捉项目以调整上下对称)。我还需要在应用程序启动时从特定项目开始 - 启动。
我正在使用 pointerInteropFilter 能够在这些操作中运行一些代码:向下、移动、向上。当我点击时代码运行正常,但在移动完成后它不会触发 ACTION_UP。
[这是我从屏幕上松开手指后想要的结果......即......“跳转”或滚动到在这种情况下为项目 10 和一些偏移量的值][1]
该代码仅适用于点击...但是当 Action_up 时协程不起作用
我读到我们被建议使用 \"prefer pointerInput] 并仅将其用于与
- 消耗 [MotionEvent]s 的现有代码\"
它还说 pointerinteropFilter 尝试在视图和运动事件之间进行无缝处理......但我不知道它是否相关。
谢谢。
毛里西奥
@Composable
fun Greeting(name: String) {
val listState2 = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
LazyColumn(
state = listState2,
) {
items (50) {index ->
Text(
modifier = Modifier
.pointerInteropFilter {
when (it.action) {
MotionEvent.ACTION_DOWN -> {
Log.i(ContentValues.TAG, \"down pressed\")
false
}
MotionEvent.ACTION_MOVE -> {
Log.i(ContentValues.TAG, \"moved done\")
false
}
MotionEvent.ACTION_UP -> {
coroutineScope.launch {
listState2.scrollToItem(10, 28)
}
Log.i(ContentValues.TAG, \"up detected\")
}
MotionEvent.ACTION_CANCEL -> {
coroutineScope.launch {
listState2.scrollToItem(10, 28)
}
Log.i(ContentValues.TAG, \"canceled chosen\")
false
}
else ->
false
}
true
},
text = \"item $index\",
)
}
}
}```
[1]: https://i.stack.imgur.com/vSiCG.png
-
忘了说我尝试为父级(lazycolumn)标记 FALSE 以避免它消耗事件......但这并没有改变问题。
标签: pointers input android-jetpack-compose action motionevent