(Transferred from: http://blog.csdn.net/angle_rupert/article/details/6255522)
Statement:
1 float x_temp01 = 0.0f; 2 float y_temp01 = 0.0f; 3 float x_temp02 = 0.0f; 4 float
Ontouchevent method for overriding activity:
1 @Override2 Public Booleanontouchevent (motionevent event)3 {4 //get current coordinates5 floatx =event.getx ();6 floaty =event.gety ();7 8 Switch(Event.getaction ())9 {Ten CaseMotionevent.action_down: One { AX_TEMP01 =x; -Y_TEMP01 =y; - } the Break; - Casemotionevent.action_up: - { -X_TEMP02 =x; +Y_TEMP02 =y; - + if(X_temp01!=0 && y_temp01!=0)// A { at //Compare X_TEMP01 and X_temp02 - //X_TEMP01>X_TEMP02//left - //X_TEMP01==X_TEMP02//In a vertical direction or not moving . - //X_TEMP01<X_TEMP02//Right - - if(X_TEMP01>X_TEMP02)//left in { - //moved the X_TEMP01-X_TEMP02 to } + - if(X_TEMP01<X_TEMP02)//Right the { * //moved the X_TEMP02-X_TEMP01 $ }Panax Notoginseng } - } the Break; + CaseMotionevent.action_move: A { the + } - Break; $ $ } - return Super. Ontouchevent (event); -}
Note that the test is feasible, simple and useful;
Change your own decision whether to swipe:
1 CaseMotionevent.action_down: {2Ismove =false;3downx=x;4downy=y;5 Break;6 }7 Casemotionevent.action_up: {8UpX =x;9upy=y;Ten if((upx-downx!=0) | | (upy-downy!=0)) OneIsmove=true; A Else -Ismove=false; - Break; the}
Android Android to determine whether to swipe