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.