簡體   English   中英

觸摸屏時如何保留onTouchEvent?

[英]How to retain onTouchEvent while touching screen?

觸摸屏幕時,有以下方法可以處理:

public boolean onTouchEvent(MotionEvent event) {

    boolean touchDown = true;
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            Log.i(TAG,"touching the screen: YES");
        case MotionEvent.ACTION_UP:
            touchDown = false;
            Log.i(TAG,"touching the screen: NO");
    }
    return touchDown;

}

當我不移動手指就觸摸屏幕時,Logcat的結果是:

touching the screen: YES
touching the screen: NO

在從屏幕上釋放myfinger之前,我不希望顯示第二個日志。

我做錯了什么?

謝謝。

你需要break; 在您的第一個(和第二個)案例中。 我也為此感到ung惱。 :)

暫無
暫無

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

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