Android游戏开发教程之十九:屏幕双击事件的捕获
2012-08-05 22:24
531 查看
在Android游戏开发中,我们可能经常要像PC操作一样在屏幕上双击。对于屏幕双击操作,Android 1.6版本以前并没有提供完善的手势识别类,Android 1.5的SDK中提供了android.view.GestureDetector.OnDoubleTapListener,但经测试无法正常工作,不知是何原因。最终我们的解决方案如下面的代码:
public class TouchLayout extends RelativeLayout { public Handler doubleTapHandler = null; protected long lastDown = -1; public final static long DOUBLE_TIME = 500; public TouchLayout(Context context) { super(context); } public TouchLayout(Context context, AttributeSet attrs) { super(context, attrs); } public TouchLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public boolean onTouchEvent(MotionEvent event) { this.handleEvent(event); if (event.getAction() == MotionEvent.ACTION_DOWN) { long nowDown = System.currentTimeMillis(); if (nowDown - lastDown < DOUBLE_TIME) { if (doubleTapHandler != null) doubleTapHandler.sendEmptyMessage(-1); } else { lastDown = nowDown; } } return true; } protected void handleEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //Do sth 这里处理即可 break; case MotionEvent.ACTION_UP: //Do sth break; } } }
相关文章推荐
- Android游戏开发教程之一:长按事件的原理
- Android 屏幕双击事件的捕获简单示例
- Android游戏开发教程之十八:屏幕分辨率汇总
- Android游戏开发教程------(绘制屏幕)
- Android应用程序入门 推箱子游戏开发(二) 键盘事件监听 角色在屏幕上移动
- Android游戏开发之旅(二十) 双按事件捕获
- Android游戏开发教程之十四:按键中断事件的处理
- Android游戏开发系列教程第三讲(事件处理)
- Android游戏开发&Android软件开发【教程三十二篇】
- android开发教程之textview内容超出屏幕宽度显示省略号
- Android游戏开发系列教程第二讲(基本图形绘制)
- Android游戏开发视频教程下载(Android4.3、Cocos2d-x、Untity2D/3D、跨平台引擎技术)
- Android游戏开发系列教程第五讲(后台服务)
- 【Android游戏开发十九】(必看篇)SurfaceView运行机制详解—剖析Back与Home按键及切入后台等异常处理!
- 【iOS-cocos2d-X 游戏开发之十五】Cocos2dx中响应Android的Back(返回)与Menu(小房子)事件&&Cocos2dx自动释放粒子内存函数!
- Android开发_libgdx游戏引擎教程 ApplicationListener,着手第一个程序! (六)
- Android游戏开发11:Android SDK自带draw9patch工具详细教程
- 【Android游戏开发十九】(必看篇)SurfaceView运行机制详解—剖析Back与Home按键及切入后台等异常处理!
- 【Android 开发教程】检测屏幕的方向
- [置顶] 史上最全的安卓修炼之路Android开发视频教程安卓软件游戏开发视频教程+案例项目源码