本文介绍了LongPress之后移动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的GestureDetector中校准LongPress之后,如何收听移动事件?

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

当用户LongClick进入选择模式时,可以将一个正方形拖到屏幕中.但是我注意到在使用LongPress之后,不会调用onScroll.

When the user LongClick he starts the selection mode, and can drag a square into the screen. But I noticed that the onScroll is not called after LongPress is consumed.

推荐答案

试图解决这一问题已有一段时间,目前的解决方案是:

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

  1. 在gestureDetector上使用setIsLongpressEnabled(isLongpressEnabled)禁用longpress

这是我的View的OnTouch方法:

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

每当我将手指放在屏幕上时,设备都会返回ACTION_MOVE.如果您不这样做,则只需使用计时器或线程在0.5秒后检查某些按下标志的状态即可.

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.

希望有帮助!

这篇关于LongPress之后移动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-18 03:06