I have introduced the issue of inter-activity animation jump in a previous blog, but the real software discovery does not meet our requirements, because 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.
<? 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: export Tx = "69.99999%" Android: Ty = "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: export Tx = "69.99999%" Android: Ty = "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: export Tx = "50.0%" Android: Ty = "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: export Tx = "50.0%" Android: Ty = "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 string. 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"Android: theme = "@ style/themeactivity"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>
OK, so we can achieve the animation jump of the public comments activity. Let's try it on your own.
Recently, the company's projects have been busy, and some friends in the blog need to leave a message.Source codeI have uploaded most of them to group sharing. Please download them by yourself!