This feature allows you to register a logon page on a mobile phone similar to Android. When a gesture slides down, the page is closed.
Use GestureDetector to achieve this effect. When the gesture slides on the screen, the onFling method is used. Therefore, you can make a judgment and operation in this method.
Well, as an old programmer, I will not talk about the principle. I believe you will understand it. If you have any questions, please leave a message or contact me. I will reply immediately.
The effect is as follows:
Private GestureDetector mGestureDetector; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. layout_login); mGestureDetector = new GestureDetector (this, new GestureDetector. simpleOnGestureListener () {@ Override public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {// if (Math. abs (e1.getRawX ()-e2.getRawX ()> 250) {// System. out. println ("the horizontal movement distance is too large"); // return true; //} if (Math. abs (velocityY) <100) {// System. out. println ("fingers moving too slowly"); return true;} // gesture down if (e2.getRawY ()-e1.getRawY ()> 200) {finish (); // disable return true here;} // gesture up if (e1.getRawY ()-e2.getRawY ()> 200) {return true;} return super. onFling (e1, e2, velocityX, velocityY );}});}
2. Similarly, if you want to control the Left and Right slides, you can use the getRawX () method directly.
3. Implement the animation effect. Rewrite the animation effects of pumping and pulling down. You can use a method that comes with Android to call the finish () method:
OverridePendingTransition (R. anim. slide_up_in, R. anim. slide_up_out );
R. anim. slide_up_out
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="200" android:fromYDelta="0%" android:interpolator="@android:anim/accelerate_interpolator" android:toYDelta="100%" /></set>
R. anim. slide_up_in:
<set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromYDelta="-100%" android:interpolator="@android:anim/accelerate_interpolator" android:toYDelta="0%" /></set>
Try it now!