Case study of Android activity animation jump

Source: Internet
Author: User

I have introduced the issue of animation jump between activities, but the actual software discovery does not meet our requirements, because the overridePendingTransition (int enterAnim, intexitAnim) this function can only be used to enter the animation of another activity. When the other activity exits, the system animation is used. So here we will explain how to set the animation jump and exit jump of all activities. In fact, some software has already done so, such as the Public Comment network that we are familiar.
Next, let's take an example to see how to achieve the animation jump of all activities. Here we may wish to simulate the animation jump of the public comments online activity.
First, create anim_enter.xml in layout/anim.

<set android:interpolator="@android:anim/decelerate_interpolator"       xmlns:android="http://schemas.android.com/apk/res/android">       <scale android:duration="@android:integer/config_mediumAnimTime" android:pivotX="69.99999%" android:pivotY="100.0%" android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" />       <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="0.0" android:toAlpha="1.0" />   </set>  

Anim_exit.xml

<?xml version="1.0" encoding="UTF-8"?>   <set android:interpolator="@android:anim/accelerate_interpolator"    xmlns:android="http://schemas.android.com/apk/res/android">       <scale android:duration="@android:integer/config_mediumAnimTime" android:pivotX="69.99999%" android:pivotY="100.0%" android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="0.0" />       <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="1.0" android:toAlpha="0.0" />   </set>  

The preceding two xml files correspond to the entry and exit animations in overridePendingTransition (int enterAnim, int exitAnim ).
Next we will define the animation effect when another activity exits, back_enter.xml

<?xml version="1.0" encoding="UTF-8"?>   <set android:interpolator="@android:anim/decelerate_interpolator"    xmlns:android="http://schemas.android.com/apk/res/android">       <scale android:duration="@android:integer/config_mediumAnimTime" android:pivotX="50.0%" android:pivotY="50.0%" android:fromXScale="1.5" android:toXScale="1.0" android:fromYScale="1.5" android:toYScale="1.0" />       <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="0.4" android:toAlpha="1.0" />   </set>  

Back_exit.xml

<?xml version="1.0" encoding="UTF-8"?>    <set android:interpolator="@android:anim/decelerate_interpolator"    xmlns:android="http://schemas.android.com/apk/res/android">        <scale android:duration="@android:integer/config_mediumAnimTime" android:pivotX="50.0%" android:pivotY="50.0%" android:fromXScale="1.0" android:toXScale="0.4" android:fromYScale="1.0" android:toYScale="0.4" />        <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="1.0" android:toAlpha="0.0" />    </set>

We have already defined the animation effect for entering and exiting. Next we need to define the style. Previously we set the animation effect to be written in the activity, just to define the animation for a single activity. Now we define animation effects for all the activities. We may wish to define a style and introduce the style to all the activity packages. In this way, we think of the application in AndroidManifest. xml. It's easy to understand all the activities in it.
Next, we need to declare the animation style in style. xml.

<style name="ThemeActivity" mce_bogus="1">       <item name="android:windowAnimationStyle">@style/AnimationActivity</item>       <item name="android:windowNoTitle">true</item>   </style>                  <style name="AnimationActivity" parent="@android:style/Animation.Activity" mce_bogus="1">       <item name="android:activityOpenEnterAnimation">@anim/anim_enter</item>       <item name="android:activityOpenExitAnimation">@anim/anim_exit</item>                <item name="android:activityCloseEnterAnimation">@anim/back_enter</item>       <item name="android:activityCloseExitAnimation">@anim/back_exit</item>       </style>

Then declare the style in AndroidManifest. xml.

<application           android:icon="@drawable/ic_launcher" <span style="color:#FF0000;"> android:theme="@style/ThemeActivity"</span>           android:label="@string/app_name" >           <activity               android:label="@string/app_name"             android:name=".GlobalAnimationActivity" >               <intent-filter >                   <action android:name="android.intent.action.MAIN" />                       <category android:name="android.intent.category.LAUNCHER" />               </intent-filter>           </activity>           <activity android:name=".OtherActivity"></activity>       </application>  

 

Related Article

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.