当前位置: 移动技术网 > IT编程>移动开发>Android > Android 屏幕双击事件的捕获简单示例

Android 屏幕双击事件的捕获简单示例

2019年07月24日  | 移动技术网IT编程  | 我要评论

沙沙劲舞王,刘洪沂女儿杀人,屁屁宽频

在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应用的朋友。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网