在 Android 中捕获双击

发布于 2024-12-27 03:14:33 字数 110 浏览 1 评论 0 原文

我正在使用 AndEngine 捕获 onSceneTouchEvent 事件。

我想要做的是不允许它捕获用户双击屏幕。

有没有办法检测双击或禁用它们?

谢谢

I am capturing the event of onSceneTouchEvent using AndEngine.

What i want to do is not allow it to capture the user double tapping the screen.

Is there anyway to detect double taps or disable them?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黒涩兲箜 2025-01-03 03:14:33

编辑:经过更多查看后,我认为这可能更适合您:

// in an onUpdate method

onUpdate(float secondsElapsed){

if(touched){
if(seconds > 2){
doSomething();
touched = false;
seconds = 0;
} else{
seconds += secondsElapsed;
}
}

}

取自: http://www.andengine.org/forums/gles1/delay-in-touchevent-t6087.html

根据上面的评论,我确信您也可以使用 SystemClock 来进行以下操作。

您可以添加延迟,类似于:

public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if(firstTap){
                thisTime = SystemClock.uptimeMillis();
                firstTap = false;
            }else{
                prevTime = thisTime;
                thisTime = SystemClock.uptimeMillis();

                //Check that thisTime is greater than prevTime
                //just incase system clock reset to zero
                if(thisTime > prevTime){

                    //Check if times are within our max delay
                    if((thisTime - prevTime) <= DOUBLE_CLICK_MAX_DELAY){

                        //We have detected a double tap!
                        Toast.makeText(DoubleTapActivity.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show();
                        //PUT YOUR LOGIC HERE!!!!

                    }else{
                        //Otherwise Reset firstTap
                        firstTap = true;
                    }
                }else{
                    firstTap = true;
                }
            }
            return false;
        }

取自 OnTap 侦听器实现

EDIT: After looking around some more, I think this may better suit you:

// in an onUpdate method

onUpdate(float secondsElapsed){

if(touched){
if(seconds > 2){
doSomething();
touched = false;
seconds = 0;
} else{
seconds += secondsElapsed;
}
}

}

Taken from: http://www.andengine.org/forums/gles1/delay-in-touchevent-t6087.html

Based on the comment above, I'm sure you can finagle something with the following too, using SystemClock.

You can get away with adding a delay, something similar to this:

public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if(firstTap){
                thisTime = SystemClock.uptimeMillis();
                firstTap = false;
            }else{
                prevTime = thisTime;
                thisTime = SystemClock.uptimeMillis();

                //Check that thisTime is greater than prevTime
                //just incase system clock reset to zero
                if(thisTime > prevTime){

                    //Check if times are within our max delay
                    if((thisTime - prevTime) <= DOUBLE_CLICK_MAX_DELAY){

                        //We have detected a double tap!
                        Toast.makeText(DoubleTapActivity.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show();
                        //PUT YOUR LOGIC HERE!!!!

                    }else{
                        //Otherwise Reset firstTap
                        firstTap = true;
                    }
                }else{
                    firstTap = true;
                }
            }
            return false;
        }

Taken from OnTap listener implementation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文