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应用的朋友。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下