Move Events AFTER LongPress

后端 未结 2 883
[愿得一人]
[愿得一人] 2021-02-04 09:56

How can I listen the move events after the LongPress is caled in my GestureDetector?

When the user LongClick he starts the selection mode, and can drag a square into the

2条回答
  •  清酒与你
    2021-02-04 10:23

    Tried to do fight this for a while, and for now the solution is:

    1. Disable the longpress using setIsLongpressEnabled(isLongpressEnabled) on your gestureDetector

    Here is my OnTouch method of my View:

    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;
        }
    

    My device returned ACTION_MOVE whenever I hold finger on the screen. If your doesnt, just check the state of some pressed flag after 0.5s using a timer or thread.

    Hope that helps!

提交回复
热议问题