Now a lot of apps will appear Android to achieve the rotation around the center of the Guide page effect, a similar car has been moving forward on the Rotary animation effect.
First look at the preview effect:
Well, the overall effect is also ideal, the basic implementation of the page around the center of the bottom of the screen rotation.
Here we use a component Viewflipper of the Android system, the main function of which is to animate the view switch in it, the Main method is as follows:
- Setinanimation: Sets the animation when view enters the screen.
- Setoutanimation: Sets the animation when view exits the screen.
- Shownext: Call this method to display the next view.
- Showprevious: This method can be invoked to display the previous view.
- Setfilpinterval: Sets the time interval for view switching. The parameter is milliseconds.
- Startflipping: Start the view switch.
- Stopflipping: Stop view toggle.
- Setautostart: Set whether to start automatically. If set to True, the view switch automatically starts when Viewflipper is displayed.
First look at the layout code:
<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/"
Android "android:id=" @+id/activity_main "android:layout_width=" match_parent "android:layout_height=" Match_parent " android:background= "#440000ff" > <imageview android:layout_width= "match_parent" android:layout_height= "23
0DP "android:layout_alignparentbottom=" true "android:background=" @mipmap/guide_bg "/> <relativelayout Android:layout_width= "Match_parent" android:layout_height= "match_parent" > <viewflipper android:id= "@
+ID/VF "android:layout_width=" match_parent "android:layout_height=" match_parent "> <fragment class= "Com.example.dell.guide.GuideOneFragment" android:layout_width= "Match_parent" Android:layout_heig ht= "Match_parent"/> <fragment class= "Com.example.dell.guide.GuideTwoFragment" android:layout _width= "Match_parent" android:layout_height= "Match_parent"/> <fragment class= "Com.example.dell.guide.GuideThreeFragment" Android:layout_width= "Match_parent" android:layout_height= "match_parent"/> </ViewFlipper>
;/relativelayout> </RelativeLayout>
The main is a picture of the white hemisphere at the bottom of the page, as well as the interior of the Viewflipper Three view, of course, can not fragment, use the general layout also line.
The next activity is the corresponding activity:
public class Mainactivity extends Appcompatactivity {//Handle gesture monitoring private gesturedetector detector;
Private Viewflipper Flipper;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Flipper = (viewflipper) Findviewbyid (R.ID.VF); detector = new Gesturedetector (This, new Gesturedetector.simpleongesturelistener () {@Override public boolean Onfling (motionevent E1, motionevent E2, float Velocityx, float velocityy) {if (E1.getx ()-E2.getx () > 120.0F)
{//sliding from right to left flipper.setinanimation (Mainactivity.this, r.anim.tip_left_in);
Flipper.setoutanimation (Mainactivity.this, r.anim.tip_left_out);
if (Flipper.getdisplayedchild () < 2) {flipper.shownext (); } else if (E1.getx ()-E2.getx () < -120.0f) {//sliding from left to right flipper.setinanimation Mainactivity.this, R.
ANIM.TIP_RIGHT_IN); Flipper. Setoutanimation (Mainactivity.this, r.anim.tip_right_out);
if (Flipper.getdisplayedchild () > 0) {flipper.showprevious ();
return false;
}
}); @Override public boolean ontouchevent (Motionevent event) {if (detector!= null) {return Detector.ontouc
Hevent (event);
Return Super.ontouchevent (event);
}
}
To create a Gesturedetector object, because you want to switch the page by gesture sliding:
detector = new Gesturedetector (This, new Gesturedetector.simpleongesturelistener () {
@Override public
Boolean Onfling (motionevent E1, motionevent E2, float Velocityx, float velocityy) {
//omitted ...
return false;
}
});
Because we only care about the fingers sliding around, so rewrite the Simpleongesturelistener onfling (), and then in Ontouchevent () the binding of gesture listening. Our activity will be able to slide the gesture accordingly.
In the Onfling () method, when you slide from right to left, setInAnimation()、setOutAnimation() you can see the corresponding animation effect by setting the animation from the right side of view from the flipper and exiting the animation from the left, and then calling the showNext() method to start switching to the next page. When you slide from left to right, you'll also need to set up the view entry and exit animations, and then showPrevious() switch to the previous page by using the method.
The specific animation file can refer to the source code, here is not posted. SOURCE download
The entire implementation process is covered.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.