Reputation: 2984
What is the difference of events of onFling() and onScroll() of android.view.GestureDetector.OnGestureListener? link text
Upvotes: 2
Views: 5158
Reputation: 61
You can see the code of framework/base/core/java/android/view/GestureDetector.java
, at the onTouchEvent()
method. onFling()
is called in case of MotionEvent.ACTION_UP
and velocityY > mMinimumFlingVelocity
or velocityX > mMinimumFlingVelocity
. onScroll()
is called in case of MotionEvent.ACTION_MOVE
.
Upvotes: 2
Reputation: 2690
Actually onFling has nothing to do with the speed at which the movement ocurred. It's the user, via the velocityX and velocityY parameters that determine if the speed (or distance, via the MotionEvent parameters) was good enough for their purposes.
The onScroll is constantly called when the user is moving his finger, where as the onFling is called only after the user lifts his finger.
Upvotes: 3
Reputation: 2289
You can differentiate between the two after the onFling() happens. First, in onDown() store the current coordinates of the image as class variables. The onScroll() will work as expected but if the onFling() determines that this is a fling event, just restore the original coordinates that were stored in onDown(). I found this works very well.
@Override
public boolean onDown(MotionEvent e) {
// remember current coordinates in case this turns out to be a fling
mdX = imageView.dX;
mdY = imageView.dY;
return false;
}
Upvotes: 1
Reputation: 98501
onScroll() happens after the user puts his finger down on the screen and slides his finger across the screen without lifting it. onFling() happens if the user scrolls and then lifts his finger. A fling is triggered only if the motion was fast enough.
Upvotes: 10