沙沙劲舞王,刘洪沂女儿杀人,屁屁宽频
在android游戏开发中,我们可能经常要像pc操作一样在屏幕上双击。对于屏幕双击操作,android 1.6版本以前并没有提供完善的手势识别类,android 1.5的sdk中提供了android.view.gesturedetector.ondoubletaplistener,但经测试无法正常工作,不知是何原因。最终我们的解决方案如下面的代码:
java代码
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 studio 解决logcat无过滤工具栏的操作
Android Studio 恢复小窗口停靠模式(Docked Mode)
Android studio保存logcat日志到本地的操作
Android Studio快捷键生成TAG、Log.x日志输出介绍
网友评论