在安卓系统中捕获双击事件

4

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

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

是否有任何方法可以检测双击或禁用双击?

谢谢。


1
你看过这个解决方案吗?https://dev59.com/JVnUa4cB1Zd3GeqPZE18使用系统时钟来计时延迟?那可能会有所帮助。 - TryTryAgain
嗯,有趣。如果您提供一个这样的答案示例,我会标记它为正确。 - coder_For_Life22
很高兴能帮到你。我刚刚在回答中添加了另一个解决方案,不妨也试一试 :-) - TryTryAgain
1个回答

3

编辑:经过进一步查找,我认为这个可能更适合你:

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

Taken from OnTap listener implementation


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接