Android implements page animation switching during Activity jump and finish,

Source: Internet
Author: User

Android implements page animation switching during Activity jump and finish,

Today, when shenyang binzi was working on an APP, the customer's demand was changed by adding an animation switch to the page in the original program, similar to the IPhone's left-out and right-in method, returns the opposite result. I know there are two ways to achieve this. One is to switch the animation by executing the overridePendingTransition method after startActivity, and the same is true for finish. The following is the encapsulated method:

/***** @ Description: The effect of the left-out and right-in jump to the page * @ Method_Name: startActivityAnim * @ param activity * @ return: void * @ Creation Date: 10:20:37 * @ version: v1.00 * @ Author: JiaBin * @ Update Date: * @ Update Author: JiaBin */public static void startActivityAnim (Activity activity, Class <?> TLS) {Intent intent = new Intent (); intent. setClass (activity, linoleic); activity. startActivity (intent); // set the animation to switch from the right to exit the activity on the left. overridePendingTransition (R. anim. in_from_right, R. anim. out_to_left );}

Then read the original Coder code (a headache ~~~) I found that using my common method can meet the customer's needs, but there will be a lot of changes, which is a headache, so I want to use the second method, through xml configuration, make every one in AndroidManifest. the activities registered in xml are referenced in the configuration so that the customer's results can be achieved and the project can be changed to the minimum extent. The following is a method:

1. 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 and select the theme of every Activity in AndroidManifest. xml that requires this effect. The Code is as follows:

<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>
In the preceding three steps, you can switch between the animations that access the jump Activity. The corresponding animation files are attached below.

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="500"        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="500"        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="500" /><alpha android:fromAlpha="0.1" android:toAlpha="1.0"android:duration="500" /></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="500" /><alpha android:fromAlpha="1.0" android:toAlpha="0.1"android:duration="500" /></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="500" /><alpha android:fromAlpha="0.1" android:toAlpha="1.0"android:duration="500" /></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="500" /><alpha android:fromAlpha="1.0" android:toAlpha="0.1"android:duration="500" /></set>

The above is the fragment code that needs to be used. If you need it, you can write the animation effect on your own and then meet your needs.

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.