Added left and right gesture recognition for the activity in Android development, for example, sliding right to close the current page
/** For left and right gestures * 1. copy the following content to the target activity * 2. the oncreate () of the target activity calls initgesture () * 3. the target activity must be implements ontouchlistener, ongesturelistener */private listener; private int verticalmindistance = 180; private int minvelocity = 0; private void initgesture () {listener = new listener) this);} public Boolean onfling (motionevent E1, motionevent E2, float velocityx, float velocityy) {If (e1.getx ()-e2.getx ()> verticalmindistance & math. ABS (velocityx)> minvelocity) {// switch activity // intent = new intent (viewsnsactivity. this, updatestatusactivity. class); // startactivity (intent); // toast. maketext (this, "gesture to the left", toast. length_short ). show ();} else if (e2.getx ()-e1.getx ()> verticalmindistance & math. ABS (velocityx)> minvelocity) {// switch activity // intent = new intent (viewsnsactivity. this, updatestatusactivity. class); // startactivity (intent); // toast. maketext (this, "gesture to the right", toast. length_short ). show (); finish (); overridependingtransition (R. anim. push_right_in, R. anim. push_right_out);} return false;} @ override public void onlongpress (motionevent arg0) {// todo auto-generated method stub} @ override public Boolean onscroll (motionevent arg0, motionevent arg1, float arg2, float arg3) {// todo auto-generated method stub return false;} @ override public void onshowpress (motionevent arg0) {// todo auto-generated method stub} @ override public Boolean onsingletapup (motionevent arg0) {// todo auto-generated method stub return false ;} @ override public Boolean ontouch (view V, motionevent event) {// todo auto-generated method stub return mgesturedetector. ontouchevent (event) ;}@ override public Boolean ondown (motionevent arg0) {// todo auto-generated method stub return false;} @ override public Boolean dispatchtouchevent (motionevent eV) {mgesturedetector. ontouchevent (EV); return Super. dispatchtouchevent (EV );}
Add left and right gesture recognition for activity