2

我遇到了 MotionEvent.ACTION_UP 问题 在我抬起手指之前调用了该事件。

这是我正在使用的代码。我应该改变什么?谢谢你的帮助!

public boolean onTouchEvent(MotionEvent e) {
    switch(e.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if(checkColide(e.getX(), e.getY())) {
            isFootballTouched = true;
            downT = c.MILLISECOND;
            downX = e.getX();
        }
        break;
    case MotionEvent.ACTION_MOVE:
        //moveFootball(e.getX(), e.getY());
        break;
    case MotionEvent.ACTION_UP:
        upT = c.MILLISECOND;
        upX = e.getX();
        getVelocity();          
        break;
    }       
    return false;       
}
4

2 回答 2

3

如果发生这 3 种情况之一,请尝试返回 true

 public boolean onTouchEvent(MotionEvent e) {
switch(e.getAction()) {
case MotionEvent.ACTION_DOWN:
    if(checkColide(e.getX(), e.getY())) {
        isFootballTouched = true;
        downT = c.MILLISECOND;
        downX = e.getX();
    }
    return true;
case MotionEvent.ACTION_MOVE:
    //moveFootball(e.getX(), e.getY());
    return true;
case MotionEvent.ACTION_UP:
    upT = c.MILLISECOND;
    upX = e.getX();
    getVelocity();          
    return true;
}       
return false;       

}

于 2012-09-16T19:45:19.213 回答
1

可能你应该trueonTouchEvent(). 返回false意味着您不再有兴趣接收对此的事件View。希望这可以帮助。

于 2012-09-16T19:45:45.643 回答