Mar*_*los 11 android listener gesturedetector
在我的GestureDetector中使用LongPress后,如何收听移动事件?
当用户LongClick他启动选择模式时,可以将一个方块拖入屏幕.但我注意到在使用LongPress后没有调用onScroll.
Luk*_*kas 18
试图做一段时间的斗争,现在的解决方案是:
这是我的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;
}
Run Code Online (Sandbox Code Playgroud)
每当我在屏幕上按住手指时,我的设备都会返回ACTION_MOVE.如果你没有,只需使用定时器或线程检查0.5秒后的某些按下标志的状态.
希望有所帮助!