使用 GestureDetector onScroll 实现滚动延迟
我使用 GestureDetector
在自定义 View
内实现滚动。我的实现基于此:惯性滚动和边缘阻力/回弹
我注意到滚动开始之前有短暂的停顿:我检查了 onScroll
消息并注意到第一个只有在手指进行较大移动后才会到达,这会在滚动开始时导致明显的滞后。之后滚动就顺畅了。
似乎 GestureDetector 仅在运动事件之间的最小距离之后才开始发送 onScroll 消息,以确保手势不是长按或点击(顺便说一句,我设置了 setIsLongpressEnabled(false) ))。
有没有办法改变这种行为并创建平滑的滚动,而无需使用低级触摸事件实现自定义滚动手势?
I use GestureDetector
to implement scrolling inside a custom View
. My implementation is based on this: Smooth scrolling with inertia and edge resistance/snapback
I noticed a short pause before the scrolling starts: I examined the onScroll
messages and noticed that the first one arrives only after a larger movement of a finger, which causes noticable lag at the beginning of the scrolling. After that the scrolling is smooth.
It seems GestureDetector
starts sending onScroll
messages only after a minimal distance between the motionevents to make sure the gesture is not a longtap or tap (btw I set setIsLongpressEnabled(false)
).
Is there any way to change this behaviour and create a smooth scroll without implementing a custom scroll gesture using low level touch events?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案是否定的,您必须创建自己的
GestureDetector
。如果你查看Android源代码(GestureDetector.java) 第 524 到 540 行用于检测“触摸” slop”用于单次水龙头。具体来说,第 528 行阻止调用 onScroll 事件,直到移动超出触摸斜面(从视图配置中拉出)。您无法更改视图配置,并且斜率硬编码为 16 像素。这是导致您看到的滞后的半径。The answer is no, you have to create your own
GestureDetector
. If you look at the Android source code (GestureDetector.java) lines 524 to 540 are use to detect the "touch slop" for a single tap. Specifically line 528 prevents theonScroll
event from being called until the movement is outside the touch slop (which is pulled from the view configuration). You cannot change the view configuration and the slop is hard coded at 16 pixels. This is the radius that causes the lag that you are seeing.您可以使用反射将
mTouchSlopSquare
从 GestureDetector.java另外,这里是更改 GestureDetectorCompat.java< /a>
You can use reflection to change
mTouchSlopSquare
from GestureDetector.javaAlso, here is the method to change the slop for the GestureDetectorCompat.java