Android screen Double-click event Capture Simple Example _android

Source: Internet
Author: User

In Android game development, we may often have to double click on the screen like a PC operation. For screen-double-clicking, the Android 1.6 version did not provide a perfect gesture recognition class before, Android The 1.5 SDK provides Android.view.GestureDetector.OnDoubleTapListener, but the test does not work properly, for unknown reasons. Ultimately our solution is like the following code:

Java code

public class Touchlayout extends Relativelayout {public Handler doubletaphandler = null;  
  protected Long Lastdown =-1;  
 
  
 Public final static long double_time = 500;  
     
  Public Touchlayout {Super (context);  
     
  Public Touchlayout (context, AttributeSet attrs) {Super (context, attrs);  
     
  Public Touchlayout (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 can be processed here BR  
 
    Eak  
    Case MOTIONEVENT.ACTION_UP://do sth;  }  
 
   }  
 
 
}

The above is a sample code for the event capture of the Android screen, followed by additional information, hoping to help develop a friend of Android applications.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.