Android:MotionEvent Action_up do do and action_cancel do do do
我正在制作Instagram之类的视频故事。所以我遇到了手势的问题。
问题是,当我执行这些动作时,Action_Cancel处理并且Action_up如果抬起手指
- ,我会在ViewPager的第一页上打电话,并且我很迅速地向左滑动(我的手指仍然在屏幕上)
- 我' m在ViewPager的中间,我向左滑动左或右 - 左或左右,但没有完成滑动,我仍然在当前页面上,我的手指在屏幕上,
- 我在屏幕上连混在一起(我的手指仍然在屏幕上),
因此,如果我在Action_Cancel打电话后举起手指,我的视频停留在“暂停”状态
最后,问题是:我如何处理Action_Cancel之后的Action_up事件?
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
if (gestureDetector?.onTouchEvent(event) == true) return true
when (event?.actionMasked) {
MotionEvent.ACTION_DOWN -> {
viewModel.videoPause()
}
MotionEvent.ACTION_UP -> {
viewModel.videoResume()
}
MotionEvent.ACTION_CANCEL -> {
// Handles when doing these moves and ACTION_UP doesn't call if I raise my finger
// 1. I'm in 1st page of ViewPager and I swipe left->right fastly (my finger still on screen)
// 2. I'm in the middle of ViewPager and I swipe left->right or right->left, but not finishing the swipe
// and I'm still in the current page and my finger on screen
// 3. I'm moving chaosly on screen (my finger still on screen)
// So if I raise my finger after ACTION_CANCEL called, my video stay in "PAUSE" state
}
else -> { }
}
return true
}
I'm making video stories like instagram. So I met a problem with gestures.
The problem is that ACTION_CANCEL handled when I'm doing these moves and ACTION_UP doesn't call if I raise my finger
- I'm in 1st page of ViewPager and I swipe left->right fastly (my finger still on screen)
- I'm in the middle of ViewPager and I swipe left->right or right->left, but not finishing the swipe and I'm still in the current page and my finger on screen
- I'm moving chaosly on screen (my finger still on screen)
So if I raise my finger after ACTION_CANCEL called, my video stay in "PAUSE" state
Finally, question is: How I can handle Action_Up event after Action_Cancel?
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
if (gestureDetector?.onTouchEvent(event) == true) return true
when (event?.actionMasked) {
MotionEvent.ACTION_DOWN -> {
viewModel.videoPause()
}
MotionEvent.ACTION_UP -> {
viewModel.videoResume()
}
MotionEvent.ACTION_CANCEL -> {
// Handles when doing these moves and ACTION_UP doesn't call if I raise my finger
// 1. I'm in 1st page of ViewPager and I swipe left->right fastly (my finger still on screen)
// 2. I'm in the middle of ViewPager and I swipe left->right or right->left, but not finishing the swipe
// and I'm still in the current page and my finger on screen
// 3. I'm moving chaosly on screen (my finger still on screen)
// So if I raise my finger after ACTION_CANCEL called, my video stay in "PAUSE" state
}
else -> { }
}
return true
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
> action_cancel :
You don't get an
ACTION_UP
after anACTION_CANCEL
:实际上,有一种方法可以做到这一点。
将其添加到您的父级视图中。这将在手指移动时向您显示手指的位置。而且(我不知道),但是当您握住手指时,它也会触发动作。因此,每当触发操作时,您就会知道用户握住他的手指,或者每当X或Y坐标不在父级视图之外时,就可以像用户握住手指一样对待它。 (我从一个帆布问题[https://stackoverflow.com/questions/21846584/android-canvas-draw-by finger])
Actually there is a way to do this.
Add this to your parent View. This will show you the location of your finger whenever it moves. And (I don't know how) but when you hold your finger, it also triggers the action up. So whenever the action up is triggered, you'll know that the user held his finger, or whenever the x or y coordinates are outside of your parent view, you can treat it as if the user held his finger. (I got this idea from a canvas question [https://stackoverflow.com/questions/21846584/android-canvas-draw-by-finger])