android - 在 LongPress 之后移动事件

标签 android listener gesturedetector

在我的 GestureDetector 中调用 LongPress 后,如何监听移动事件?

当用户 LongClick 时,他开始选择模式,并且可以将一个正方形拖到屏幕中。但是我注意到在消费了 LongPress 之后,并没有调用 onScroll。

最佳答案

尝试过一段时间,现在的解决方案是:

  1. 在 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/

相关文章:

java - 向图像添加 Action 监听器

flutter - 有没有更好的方法来检查#flutter 中的左/右拖动?

android - ScaleGestureDetector.OnScaleGestureListener.onScaleEnd() 方法没有被击中

android - 在 ImageView android 中缩放部分图像

android - CheckBox[] 与 onClickListener[]?

Android Studio : App crashes after adding Firebase

java - 安卓 : Implement Broadcast Receiver for ClipboardManager

flutter - Flutter InkWell小部件未通过容器的渐变和颜色显示

java - 如何从另一个类调用 Activity 中的方法

android - 将两个按钮更改为切换按钮