在我的 GestureDetector 中调用 LongPress 后,如何监听移动事件?
当用户 LongClick 时,他开始选择模式,并且可以将一个正方形拖到屏幕中。但是我注意到在消费了 LongPress 之后,并没有调用 onScroll。
最佳答案
尝试过一段时间,现在的解决方案是:
- 在 gestureDetector 上使用 setIsLongpressEnabled(isLongpressEnabled) 禁用长按
这是我的 View 的 OnTouch 方法:
public boolean onTouchEvent(MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)== true)
{
//Fling or other gesture detected (not logpress because it is disabled)
}
else
{
//Manually handle the event.
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
//Remember the time and press position
Log.e("test","Action down");
}
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
//Check if user is actually longpressing, not slow-moving
// if current position differs much then press positon then discard whole thing
// If position change is minimal then after 0.5s that is a longpress. You can now process your other gestures
Log.e("test","Action move");
}
if (event.getAction() == MotionEvent.ACTION_UP)
{
//Get the time and position and check what that was :)
Log.e("test","Action down");
}
}
return true;
}
只要我将手指放在屏幕上,我的设备就会返回 ACTION_MOVE。如果您不这样做,只需在 0.5 秒后使用计时器或线程检查某些按下标志的状态。
希望对您有所帮助!
关于android - 在 LongPress 之后移动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5651082/