4

这是一些简单的android代码:

@Override
public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            // do something
            break;
        case MotionEvent.ACTION_MOVE:
            // do something
            // how to trigger a ACTION_DOWN event here?
            break;
}

我想ACTION_DOWN在处理ACTION_MOVE. 是否可以?

4

1 回答 1

7

你可以这样试试。

@Override
public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            // do something
            break;
        case MotionEvent.ACTION_MOVE:
            // do something
            // how to trigger a ACTION_DOWN event here?
            event.setAction(MotionEvent.ACTION_DOWN);
            onTouch(v,event);
            break;
             }
}
于 2012-11-23T12:12:03.007 回答