无论Android中是什么,MotionEvents都会触发

时间:2016-12-30 10:19:08

标签: java android android-touch-event

我在Android中有我的MotionEvents的代码:

@Override
public boolean onTouchEvent(MotionEvent event){

    int action = event.getActionMasked();

    switch (action){
        case MotionEvent.ACTION_UP:
            mGameview.moveUp(30);
            break;
        case MotionEvent.ACTION_DOWN:
            mGameview.moveDown(30);
            break;
    }

    return true;
}

然而,当我向上/向下拖动手指时,它们不会触发,而是无论我在应用程序中做什么,它们都会同时发生,例如当我点击时,左右拖动。

1 个答案:

答案 0 :(得分:0)

尝试通过以下方式采取行动:

int action = event.getAction() & MotionEvent.ACTION_MASK;