首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MotionEvent.Action_up已提前调用

MotionEvent.Action_up已提前调用
EN

Stack Overflow用户
提问于 2012-09-17 03:41:11
回答 2查看 1.5K关注 0票数 2

我与MotionEvent.ACTION_UP有一个问题,在我举起手指之前,事件被调用了。

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

代码语言:javascript
复制
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;       
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-17 03:45:19

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

代码语言:javascript
复制
 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;       

}

票数 3
EN

Stack Overflow用户

发布于 2012-09-17 03:45:46

也许您应该从onTouchEvent()返回true。返回false意味着您对接收此View的事件不再感兴趣。希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12450109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档