Toggle Animation for Android activity

Source: Internet
Author: User

There is too much of a way to jump between activity in the app ... Want to change it? Then write it yourself,!!!!!!.

There are two ways to achieve jumps between acitvity.

One, defined in the androidmanifest.

1. Now add a style to the Res/values/styles.xml, as follows

?
1 2 3 4 <style name= "Apptheme" mce_bogus= "1" parent= "@android: Style/theme.light" >          <item name= "Android:windowanimationstyle" > @style/default_animation</item>          <item name= "Android:windownotitle" >true</item> </style >

<item name= "Android:windownotitle" >true</item> this sentence is to hide the title bar, because the animation range is included in the title bar, this optional.

<item name= "Android:windowanimationstyle" > @style/default_animation</item> function is to specify an animation file. So to define a style (also in res/values/styles.xml, you can create an additional XML)

The style defined is as follows


?
1 2 3 4 5 6 7 <!--default activity jump----<style name= "Default_animation" mce_bogus= "1" parent= "@android: style/     Animation.activity "> <item name=" android:activityopenenteranimation "> @anim/default_anim_in</item> <item name= "Android:activityopenexitanimation" > @anim/anim_stay</item> <item name= "Android: Activitycloseenteranimation "> @anim/anim_stay</item> <item name=" Android:activitycloseexitanimation " > @anim/default_anim_out</item> </style>
then you define the corresponding animation file Default_anim_in,anim_stay in the Res/anim folder,Default_anim_out.


4 Item (each) represents a

Activity A jumps to activity B when activity B enters the animation;

Activity a jumps to activity B when activity a exits the animation;

Activity a enters animation when activity B returns to activity a

Activity B returns the Activityb animation when activity A is returned

The final step is to add these animations to the androidmanifest.

?
1 2 3 4 <application android:icon= "@drawable/logo" android:label= "@string/app_name" android:theme= "@style/apptheme" ;
that's all you can do. The method defined in the activity is the same as aplication, which is defined in application to all activity and overrides the animation defined in application if an animation is also defined in the activity.


The following comes with Default_anim_in,anim_stay,default_anim_out three animation files (to achieve the QQ jump rotation painting-gradient switch).

default_anim_in

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 <?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android= "Http://schemas.android.com/apk/res/android"         > <scale android:duration= "android:fromxscale=" 0.7 "android:fromyscale=" 0.7 " Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator" android:pivotx= "50%" Android :p ivoty= "50%" android:toxscale= "1" android:toyscale= "1"/> <alpha android:duration= "2 XX "android:fromalpha=" 0 "android:toalpha=" 1.0 "/> </set>


Default_anim_out

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android= "http://schemas.android.com/apk/res/ Android  >       <scale          Android:duration= "        android:fromxscale=" 1 "         android:fromyscale= "1"         android: Interpolator= "@android: Anim/accelerate_decelerate_interpolator"          android:pivotx= "50%"         android:pivoty= "50%"          android:toxscale= "0.7"          android:toyscale= "0.7"/>       <alpha          android:duration= "        android:fromalpha=" 1 "      &nBsp;  android:toalpha= "0"/>   </set>


Anim_stay

?
1 2 3 4 5 6 7 8 9 <?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android= "Http://schemas.android.com/apk/res/android" > <translate     android:duration= "0"     android:fromxdelta= "     android:fromydelta= "0"     android:toxdelta= "0"      android:toydelta= "0"/> </set>
Second, the implementation of the Code

To achieve jump animation can also be in the code oh and implementation.

Activity a jumps to activity B, adding overridependingtransition (r.anim.anim_in, R.anim.anim_out) after startactivity (intent);

Activity b returns activity A with overridependingtransition (r.anim.anim_in, R.anim.anim_out) after finish ();

Anim_in is the animation that enters activity, and Anim_out is the animation of the activity that exits .

over!!!!


Toggle Animation for Android activity

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.