The gesture recognizer realizes the interface rotation and jump, the specific content is as follows
1. Create a GestureDetector object
2. Create a new class and inherit the SimpleOnGestureListener class (the parameters required for creating GestureDetecto)
3. Rewrite the OnFling() method in SimpleOnGestureListener. (Swipe gesture monitoring)
4. Rewrite the OntouchEvent method of the interface
5. Add events through onTouchEvent() of GestureDetector object
The code is as follows:
public abstract class BaseActivity extends AppCompatActivity { private GestureDetector gue; @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_base); //The first parameter here is the context, and the second is the gesture listener gue = new GestureDetector(this, new MyGestureListener()); } class MyGestureListener extends { //The first parameter of the onFling method is the position where the finger is pressed, the second parameter is the position where the finger is released, and the third parameter is the speed of the finger @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { float startX = ();//Get the horizontal axis of the finger pressed position through () float endX = ();//Get the horizontal axis of the finger release position through () float startY = ();//Get the vertical coordinate of the finger pressed position through () float endY = ();//Get the vertical coordinate of the finger loosened by () if ((startX - endX) > 50 && (startY - endY) < 200) { //(startX - endX) > 50 is the distance between the finger from pressing to release and the horizontal coordinate is greater than 50 // (startY - endY) < 200 is the absolute value of the difference between the finger from pressing to release //The interface is implemented through Intent here } if ((endX - startX) > 50 && (startY - endY) <200) { //The interface is implemented through Intent here } //The return value is the key point: if the return value is true, the action can be executed, if it is a flash action can not be executed return true; } } @Override public boolean onTouchEvent(MotionEvent event) { (event); return (event); }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.