简体   繁体   English

MotionEvent.Action_up提前调用

[英]MotionEvent.Action_up called to early

I am having an issue with MotionEvent.ACTION_UP The event is called before I lift my finger. 我在MotionEvent.ACTION_UP上遇到问题在举起手指之前先调用该事件。

Here is the code I am using. 这是我正在使用的代码。 What should I change? 我应该改变什么? Thanks for any help! 谢谢你的帮助!

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;       
}

Try returning true if one of this 3 case occurred 如果发生这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;       

} }

Probably you should return true from the onTouchEvent() . 可能您应该从onTouchEvent()返回true Returning false means that you're not interested in receiving events to this View anymore. 返回false表示您不再有兴趣接收此View事件。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM