簡體   English   中英

MotionEvent.Action_up提前調用

[英]MotionEvent.Action_up called to early

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

如果發生這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;       

}

可能您應該從onTouchEvent()返回true 返回false表示您不再有興趣接收此View事件。 希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM