Android: MotionEvent ACTION_UP 在 ACTION_CANCEL 之后没有触发
Android: MotionEvent ACTION_UP doesn't trigger after ACTION_CANCEL
我正在制作类似 Instagram 的视频故事。所以我遇到了手势问题。
问题是当我做这些动作时 ACTION_CANCEL 得到了处理,而当我举起手指时 ACTION_UP 没有调用
- 我在 ViewPager 的第 1 页,我向左->向右快速滑动(我的手指仍在屏幕上)
- 我在 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
}
您在 ACTION_CANCEL
之后没有得到 ACTION_UP
:
ACTION_CANCEL
public static final int ACTION_CANCEL
Constant for getActionMasked()
: The current gesture has been aborted. You will not receive any more points in it. You should treat this as an up event, but not perform any action that you normally would.
我正在制作类似 Instagram 的视频故事。所以我遇到了手势问题。
问题是当我做这些动作时 ACTION_CANCEL 得到了处理,而当我举起手指时 ACTION_UP 没有调用
- 我在 ViewPager 的第 1 页,我向左->向右快速滑动(我的手指仍在屏幕上)
- 我在 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
}
您在 ACTION_CANCEL
之后没有得到 ACTION_UP
:
ACTION_CANCEL
public static final int ACTION_CANCEL
Constant for
getActionMasked()
: The current gesture has been aborted. You will not receive any more points in it. You should treat this as an up event, but not perform any action that you normally would.