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?
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 the onScroll
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With