除非先在MotionEvent.ACTION_DOWN中进行断点,否则MotionEvent.ACTION_MOVE不会触发

时间:2017-10-16 05:52:27

标签: android ontouchlistener motionevent

我的问题的简要描述:

我的动作片段似乎已正确注册到右侧视图,正常触发MotionEvent.ACTION_DOWN,但不MotionEvent.ACTION_MOVEMotionEvent.ACTION_UP

然而,我意外地发现,如果我在MotionEvent.ACTION_DOWN分支处放置一个断点,{F}会在按下F9(恢复程序)后开始激活MotionEvent.ACTION_MOVE

我似乎无法决定造成这一切的原因。你能帮助我吗?以下是有问题的代码:

    public  class MyTouchListener implements View.OnTouchListener {

    public static float sharedX,sharedY;

    public boolean onTouch(View view, MotionEvent motionEvent) {

        sharedX = motionEvent.getX();
        sharedY = motionEvent.getY();

        switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:

                ClipData data = ClipData.newPlainText("", "");
                View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
                view.startDrag(data, shadowBuilder, view, 0);
                view.setVisibility(View.INVISIBLE);
                break;

/*
            case MotionEvent.ACTION_CANCEL:

                return true;
  */

            case MotionEvent.ACTION_MOVE:
                view.setVisibility(View.VISIBLE);
                break;

            case MotionEvent.ACTION_UP:
                view.setVisibility(View.VISIBLE);
                break;
        }
        return true;
    }
    }

编辑:它可能与

有关
ACTION_CANCEL,  

后几乎立即触发
ACTION_DOWN

早于

ACTION_MOVE.

取消评论ACTION_CANCEL后,它会触发,程序永远不会达到ACTION_MOVE。

所以我现在怀疑ACTION_MOVE不起作用的原因是它之前得到了ACTION_CANCEL -ed并且整个动作事件只是退出。

0 个答案:

没有答案