make onFling and onScroll fire separately
I'm trying to write a program where gestures are detected and handled. I managed to make the onFling and the onScroll event work (these events are implemented in a listener class inside and Activity). However every time I make a swipe (onFling) the code inside the onScroll() function get executed as well. For example:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
//do something here, for example change background color to red
return true;
}
@Override
public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
//do something, for example vibrate
return true;
}
In this case when I scroll the device vibrates and that's okay. But when I make a swipe and onFling gets executed the color changes to red but it also vibrates and I don't want that.
Is there any way to prevent this, so when a swipe occurs only the code in the onFling() event gets executed and onScroll() only fires when a scrolling really happens, or if not with onScroll() but to handle simple finger movement and swipe gestures separately?
Edit: I'm using the GestureDetector class.
I'm guessing you're using GestureDetector
.
A fling can not happen with a scroll happening before it, which is why you're receiving a onScroll(...)
callback before the onFling(...)
. The onFling(...)
is called when the user lifts there finger off the screen ( ACTION_UP
) and enough velocity has been generated.