android.view.GestureDetector.OnGestureListener onFling() 与 onScroll()

发布于 2024-09-06 08:36:41 字数 218 浏览 6 评论 0原文

android.view.GestureDetector.OnGestureListener的onFling()和onScroll()事件有什么区别? 链接文本

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如歌彻婉言 2024-09-13 08:36:42

onScroll() 在用户将手指放在屏幕上并在屏幕上滑动而不抬起手指后发生。如果用户滚动然后抬起手指,则会发生 onFling()。仅当运动足够快时才会触发投掷。

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.

情话已封尘 2024-09-13 08:36:42

实际上onFling与运动发生的速度无关。用户通过速度X和速度Y参数确定速度(或距离,通过MotionEvent参数)是否足以满足其目的。

当用户移动手指时,onScroll 会不断被调用,而 onFling 仅在用户抬起手指后才会被调用。

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.

指尖上得阳光 2024-09-13 08:36:42

您可以在onTouchEvent()方法中看到framework/base/core/java/android/view/GestureDetector.java的代码。 onFling()MotionEvent.ACTION_UPvelocityY > 的情况下被调用mMinimumFlingVelocityvelocityX > mMinimumFlingVelocityonScroll()MotionEvent.ACTION_MOVE 的情况下被调用。

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.

浊酒尽余欢 2024-09-13 08:36:42

您可以在 onFling() 发生后区分两者。首先,在 onDown() 中将图像的当前坐标存储为类变量。 onScroll() 将按预期工作,但如果 onFling() 确定这是一个 fling 事件,只需恢复 onDown() 中存储的原始坐标即可。我发现这非常有效。

   @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;

}

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;

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文