문제

What is the difference of events of onFling() and onScroll() of android.view.GestureDetector.OnGestureListener? link text

도움이 되었습니까?

해결책

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.

다른 팁

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.

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.

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;

}

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top