Today I'm here to say activity toggle animation. Activity Toggle animation refers to an activity jump animation, divided into: An activity exited animation, another activity into the animation.
After android2.0, there is a way to achieve this effect--overridependingtransition (int,int). From this method, we can see that the Overridependingtransition method requires us to pass 2 parameters, the first parameter is the second activity enters the animation, the second parameter is the first activity exited animation. Not much to say, we look directly at the code
Code under the Anim file
1.in.xml code--The second activity enters the animation
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android">3 <Alpha4 Android:fromalpha= "0.0"5 Android:toalpha= "1.0"6 android:duration= " the"7 />8 9 </Set>
2.out.xml code--animation of the first activity exit
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android">3 <Alpha4 Android:fromalpha= "1.0"5 Android:toalpha= "0.0"6 android:duration= " the"7 />8 9 </Set>
Code under the layout file
1.MainActivity Layout File Code
XML code
1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical"6 Tools:context= "Com.example.Tween_Animation.Alpha_MainActivity" >7 8 <Button9 Android:id= "@+id/button_scale"Ten Android:layout_width= "Fill_parent" One Android:layout_height= "Wrap_content" A Android:text= "@string/button_stringscaleanimation" /> - - <LinearLayout the android:gravity= "Center" - Android:layout_width= "Fill_parent" - Android:layout_height= "Fill_parent" - android:orientation= "vertical" > + - <ImageView + Android:id= "@+id/imageview_scale" A Android:layout_width= "Wrap_content" at Android:layout_height= "Wrap_content" - android:src= "@drawable/ic_launcher" /> - </LinearLayout> - - </LinearLayout>
2.mainactivity2 Layout Code
XML code
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical" >6 <ImageView7 Android:layout_width= "Fill_parent"8 Android:layout_height= "Match_parent"9 Android:background= "@drawable/ic_launcher"Ten /> One </LinearLayout>
Mainactivity's Code
Java code
1 PackageCom.example.Demo4;2 3 ImportCOM.EXAMPLE.ANDROIDANIMATION.R;4 5 Importandroid.app.Activity;6 Importandroid.content.Intent;7 ImportAndroid.os.Bundle;8 ImportAndroid.view.View;9 ImportAndroid.view.View.OnClickListener;Ten ImportAndroid.widget.Button; One ImportAndroid.widget.ImageView; A - Public classMainactivityextendsActivityImplementsonclicklistener{ - PrivateButton Button =NULL; the PrivateImageView ImageView =NULL; - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); +button =(Button) Findviewbyid (R.id.button_scale); -ImageView =(ImageView) Findviewbyid (R.id.imageview_scale); +Button.setonclicklistener ( This); A } at Public voidOnClick (View v) { -Intent Intent =NewIntent (mainactivity. This, MainActivity2.class); - startactivity (intent); - overridependingtransition (r.anim.in, r.anim.out); - } - in}
MainActivity2 's Code
Java code
1 PackageCom.example.Demo4;2 3 ImportCOM.EXAMPLE.ANDROIDANIMATION.R;4 5 Importandroid.app.Activity;6 ImportAndroid.os.Bundle;7 8 Public classMainActivity2extendsactivity{9 protected voidonCreate (Bundle savedinstancestate) {Ten Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.main); A } -}
Animation changes in Android animation case 4