Android Toggle page animations for activity jumps and finish

Source: Internet
Author: User

Today Shenyangbin in doing the app, the customer needs change is in the original program to add jump page animation switch, similar to the iphone left-right in the way, return is the opposite effect. I know there are two ways to achieve this effect, one is through the startactivity after the execution of the Overridependingtransition method to animate the switch, the same finish is the same. Here's how I encapsulated it:

/** *  *  @Description    : Jump to the left and right of the page effect *  @Method_Name    : Startactivityanim *  @param activity  *  @return         : void *  @Creation Date  : 2015-1-5 a.m. 10:20:37  *  @version        : v1.00 *  @Author         : Jiabin  *  @Update Date    :  *  @Update Author  : Jiabin */public static void Startactivityanim (activity activity, class<?> CLA) {Intent Intent = new Intent (); Intent.setclass (activity, CLA); activity.startactivity (intent);//Set Toggle animation, enter from the right, exit activity.overridependingtransition on the left (r.anim.in_from_right , r.anim.out_to_left);}

That by reading the original coder code (very headache ~ ~ ~) found that, if the use of my common approach, is to achieve customer needs, but there will be a lot of changes, change is a headache, and then want to use the second method, through the XML configuration, Each activity that is registered in the Androidmanifest.xml is referenced by the configuration so that it can achieve the customer's effect and make changes to the project to a minimum extent. Here's how to paste it out:

1. First declare the following code in Style.xml:

    <style name= "animationactivity" parent= "@android: style/animation.activity" >        <item name= "Android: Activityopenenteranimation "> @anim/push_left_in</item>        <item name=" Android: Activityopenexitanimation "> @anim/push_left_out</item>        <item name=" Android: Activitycloseenteranimation "> @anim/push_right_in</item>        <item name=" Android: Activitycloseexitanimation "> @anim/push_right_out</item>    </style>

2. Declare the following code in Style.xml:

    <style name= "themesetting" >         <item name= "Android:windowanimationstyle" > @style/animationactivity </item>    </style>

3. Set the theme settings for each activity in the androidmanifest.xml that need to use the effect and select this option, as shown in the following code:

<activity            android:name= "com.nearprint.MainNewActivity"            android:label= "@string/app_name"            Android : screenorientation= "Portrait"            android:theme= "@style/themesetting<span style=" font-family:arial, Helvetica , Sans-serif; " > "></span>
The above three steps can be implemented to access the animation of the jump activity switch problem, the following paste the corresponding animation file.

In_from_right.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:interpolator= "@android: Anim/accelerate_interpolator" >    <translate        android:duration= " "        android:fromxdelta=" 100%p "        android:toxdelta=" 0%p "/></set>

Out_to_left.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:interpolator= "@android: Anim/accelerate_interpolator" >    <translate        android:duration= " "        android:fromxdelta=" 0%p "        android:toxdelta=" -100%p "/></set>

Push_left_in.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" ><translate android:fromxdelta= "100%p" android:toxdelta= "0" android:duration= "$"/><alpha android: Fromalpha= "0.1" android:toalpha= "1.0" android:duration= "$"/></set>

Push_left_out.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" ><translate android:fromxdelta= "0" android:toxdelta= " -100%p" android:duration= "$"/><alpha android: Fromalpha= "1.0" android:toalpha= "0.1" android:duration= "$"/></set>

Push_right_in.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" ><translate android:fromxdelta= " -100%" android:toxdelta= "0" android:duration= "$"/><alpha android: Fromalpha= "0.1" android:toalpha= "1.0" android:duration= "$"/></set>

Push_right_out.xml

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" ><translate android:fromxdelta= "0" android:toxdelta= "100%" android:duration= "$"/><alpha android: Fromalpha= "1.0" android:toalpha= "0.1" android:duration= "$"/></set>

The above is the need to use the fragment code, you need to get it, the animation can write their own, and then meet the needs.

Android Toggle page animations for activity jumps and finish

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.