Android 屏幕双击事件的捕获简单示例
在Android游戏开发中,我们可能经常要像PC操作一样在屏幕上双击。对于屏幕双击操作,Android1.6版本以前并没有提供完善的手势识别类,Android1.5的SDK中提供了android.view.GestureDetector.OnDoubleTapListener,但经测试无法正常工作,不知是何原因。最终我们的解决方案如下面的代码:
Java代码
publicclassTouchLayoutextendsRelativeLayout{
publicHandlerdoubleTapHandler=null;
protectedlonglastDown=-1;
publicfinalstaticlongDOUBLE_TIME=500;
publicTouchLayout(Contextcontext){
super(context);
}
publicTouchLayout(Contextcontext,AttributeSetattrs){
super(context,attrs);
}
publicTouchLayout(Contextcontext,AttributeSetattrs,intdefStyle){
super(context,attrs,defStyle);
}
publicbooleanonTouchEvent(MotionEventevent){
this.handleEvent(event);
if(event.getAction()==MotionEvent.ACTION_DOWN){
longnowDown=System.currentTimeMillis();
if(nowDown-lastDown<DOUBLE_TIME)
{
if(doubleTapHandler!=null)
doubleTapHandler.sendEmptyMessage(-1);
}else{
lastDown=nowDown;
}
}
returntrue;
}
protectedvoidhandleEvent(MotionEventevent){
switch(event.getAction()){
caseMotionEvent.ACTION_DOWN:
//Dosth这里处理即可
break;
caseMotionEvent.ACTION_UP:
//Dosth
break;
}
}
}
以上就是对Android屏幕双击的事件捕获的示例代码,后续继续补充相关资料,希望能帮助开发Android应用的朋友。
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短