Reprinted: http://ming-fanglin.iteye.com/blog/1396473
The original activity. overridependingtransition was used to customize the animation for entering the activity, but the animation for exiting cannot be defined. The results show the powerful theme and style, and you need to study it later.
Specifically, this is the case:
In androidmanifest, you can define the theme attribute for the application and activity labels. If an attribute is defined for the application, it will affect all the activities. Of course, you can overwrite it in the activity.
<Application Android: theme = "@ style/themeactivity">
Then in values/themes. xml
Java code
- <Style name = "themeactivity" mce_bogus = "1">
- <Item name = "Android: windowanimationstyle"> @ style/animationactivity </item>
- <Item name = "Android: windownotitle"> true </item>
- </Style>
<Style name = "themeactivity" mce_bogus = "1"> <item name = "Android: windowanimationstyle"> @ style/animationactivity </item> <item name = "Android: windownotitle "> true </item> </style>
In values/styles. xml
Java code
- <Style name = "animationactivity" parent = "@ Android: style/animation. Activity" mce_bogus = "1">
- <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>
<Style name = "animationactivity" parent = "@ Android: style/animation. activity "mce_bogus =" 1 "> <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>
In this way, you can define the animation in anim. This is the same as the normal animation. If you do not know it, see
Http://developer.android.com/guide/topics/graphics/view-animation.html.
In addition to defining the animation of an activity, you can also define the animation of a task and window. For details, see
Http://developer.android.com/reference/android/R.styleable.html#WindowAnimation
I don't understand what mce_bogus = "1" means. If it is removed, it has no effect.
Attached normal switching effect Animation:
An activity switching animation refers to an animation that redirects from an activity to another activity.
It consists of two parts:
Part is the animation when the first activity exits;
In the other part, the animation when the second activity enters;
In Android 2.0 and later versions, we have a function to help us implement this animation. This function is
Overridependingtransition
This function has two parameters. The first parameter is the animation when the second activity enters, and the second parameter is the animation when the first activity exits.
Note that the overridependingtransition function requires two ideas:
1. It must be called next to the startactivity () or finish () function.
2. It is applicable only to android2.0 and later versions.
The following is an example.
Overridependingtransition (R. anim. push_left_in, R. anim. push_left_out );
R. anim. push_left_in, animation when the second activity enters
Put the XML file push_left_in In the Res/anim directory.
The Code is as follows:
Java code
- <? 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 = "300"/>
- <Alpha Android: fromalpha = "0.0" Android: toalpha = "1.0" Android: Duration = "300"/>
- </Set>
<? 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 = "300"/> <Alpha Android: fromalpha = "0.0" Android: toalpha = "1.0" Android: Duration = "300"/> </set>
R. anim. push_left_out, animation when the first activity goes out
The Code is as follows:
Java code
- <Set xmlns: Android = "http://schemas.android.com/apk/res/android">
- <Translate Android: fromxdelta = "0" Android: toxdelta = "-100% P" Android: Duration = "300"/>
- <Alpha Android: fromalpha = "1.0" Android: toalpha = "0.0" Android: Duration = "300"/>
- </Set>
<Set xmlns: Android = "http://schemas.android.com/apk/res/android"> <translate Android: fromxdelta = "0" Android: toxdelta = "-100% P" Android: duration = "300"/> <Alpha Android: fromalpha = "1.0" Android: toalpha = "0.0" Android: Duration = "300"/> </set>