0

我拼命想解决这个问题:只有 ACTION_DOWN 事件触发我的方法。一整天,它工作得很好,但现在它不再工作了,但我没有改变任何东西。

 public boolean onTouch(View v, MotionEvent event) {

    boolean isReleased = event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL;
    boolean isPressed = event.getAction() == MotionEvent.ACTION_DOWN;
    boolean isMoved = event.getAction() == MotionEvent.ACTION_MOVE;


        if(isPressed){
            if(Gesture_Done){
                reset_It();         
            }
            xPressed = event.getX();
            yPressed = event.getY();
            action_timelist.add(System.currentTimeMillis());
            if(action_timelist.size()>1){
                evaluate_actionlist(true);
            }
        } 

        else if(isReleased){        
            if(!Gesture_Done){
            action_timelist.add(System.currentTimeMillis());
            evaluate_actionlist(false);
            }
            Gesture_Done=false;
        }

        else if(isMoved){
            xMoved = xPressed - event.getX();
            yMoved = yPressed - event.getY();
            checkGesture();
        }
            return false;
    } 

因为没有显示错误,我不知道如何修复它..

4

1 回答 1

3

尝试使用下面的编辑代码。几个小时前我遇到了完全相同的问题,这是因为即使我正在消费触摸事件,我也返回了 false。如果您对事件采取行动,则下面的代码返回 true,否则返回 false。

public boolean onTouch(View v, MotionEvent event) {


    boolean isReleased = event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL;
    boolean isPressed = event.getAction() == MotionEvent.ACTION_DOWN;
    boolean isMoved = event.getAction() == MotionEvent.ACTION_MOVE;


        if(isPressed){
            if(Gesture_Done){
                reset_It();         
            }
            xPressed = event.getX();
            yPressed = event.getY();
            action_timelist.add(System.currentTimeMillis());
            if(action_timelist.size()>1){
                evaluate_actionlist(true);
            }
            return true;
        } 

        else if(isReleased){        
            if(!Gesture_Done){
            action_timelist.add(System.currentTimeMillis());
            evaluate_actionlist(false);
            }
            Gesture_Done=false;
            return true;
        }

        else if(isMoved){
            xMoved = xPressed - event.getX();
            yMoved = yPressed - event.getY();
            checkGesture();
            return true;
        }
            return false;
    } 
于 2012-09-16T16:30:38.140 回答