MotionEvent没有开火

时间:2017-10-13 14:10:14

标签: java android ontouchlistener

我想实现拖放操作,但结果却非常费时,这是有问题的代码:

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);
            return true;


        case MotionEvent.ACTION_CANCEL:

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

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

虽然操作取消没有给出正确的结果(motionevent.getX不是一个理智,正常的值),但是操作取消和操作取消被触发了

其他事件都没有发生。我无法弄清楚为什么,我放弃了尝试。

0 个答案:

没有答案