android.view.GestureDetector.OnGestureListener onFling() 与 onScroll()
android.view.GestureDetector.OnGestureListener的onFling()和onScroll()事件有什么区别? 链接文本
What is the difference of events of onFling() and onScroll() of android.view.GestureDetector.OnGestureListener?
link text
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
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.
实际上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.
您可以在
onTouchEvent()
方法中看到framework/base/core/java/android/view/GestureDetector.java
的代码。onFling()
在MotionEvent.ACTION_UP
和velocityY > 的情况下被调用mMinimumFlingVelocity
或velocityX > mMinimumFlingVelocity
。onScroll()
在MotionEvent.ACTION_MOVE
的情况下被调用。You can see the code of
framework/base/core/java/android/view/GestureDetector.java
, at theonTouchEvent()
method.onFling()
is called in case ofMotionEvent.ACTION_UP
andvelocityY > mMinimumFlingVelocity
orvelocityX > mMinimumFlingVelocity
.onScroll()
is called in case ofMotionEvent.ACTION_MOVE
.您可以在 onFling() 发生后区分两者。首先,在 onDown() 中将图像的当前坐标存储为类变量。 onScroll() 将按预期工作,但如果 onFling() 确定这是一个 fling 事件,只需恢复 onDown() 中存储的原始坐标即可。我发现这非常有效。
}
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.
}