I've already talked about transforming animations, and there are 4 situations in a transform animation: Transparency animation, rotate animation, zoom animation, displacement animation.
Today I'm talking about using 4 types of transform animations to make them blend.
I'm here mainly using a listener method--setanimationlistener in a animation object. There is only one parameter in this method, the complete form of this method given by the Android API--
void Android.view.animation.Animation.setAnimationListener (Animationlistener listener). As we can see, this parameter needs to pass a parameter of type Animationlistener, we just need to use anonymous inner class (here my requirement is simple, so I use anonymous inner class). When we use the anonymous inner class, there are three methods. The code follows the Java code
1Animation1.setanimationlistener (NewAnimationlistener () {2 //called when the animation starts3 Public voidOnanimationstart (Animation Animation) {4 //TODO auto-generated Method Stub5 6 }7 //called when the animation repeats8 Public voidonanimationrepeat (Animation Animation) {9 //TODO auto-generated Method StubTen One } A //called when the animation starts - Public voidonanimationend (Animation Animation) { - //TODO auto-generated Method Stub the imageview.startanimation (animation2); - } -});
The methods Animation1 and Animation2 are animation objects.
See here how we should come true, say not much, directly paste the complete code
XML code under the Anim file
1.alpha.xml code (Animation1 loaded)
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android">3 <Alpha4 android:duration= "+"5 Android:fromalpha= "0.1"6 Android:toalpha= "1.0"7 />8 </Set>
2.translate.xml Code
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android" >3 4 <Translate5 android:duration= "+"6 Android:fromxdelta= "Ten"7 Android:fromydelta= "Ten"8 Android:toxdelta= "+"9 Android:toydelta= "+" />Ten One </Set>
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>
Activity Code
Java code
1 PackageCom.example.Demo1;2 3 4 5 ImportCOM.EXAMPLE.ANDROIDANIMATION.R;6 7 Importandroid.app.Activity;8 ImportAndroid.os.Bundle;9 ImportAndroid.view.View;Ten ImportAndroid.view.View.OnClickListener; One Importandroid.view.animation.Animation; A ImportAndroid.view.animation.Animation.AnimationListener; - Importandroid.view.animation.AnimationUtils; - ImportAndroid.widget.Button; the ImportAndroid.widget.ImageView; - /* - * Combo Animation - * Play an animation first and then play an animation + */ - Public classMainactivityextendsActivityImplementsonclicklistener{ + PrivateButton Button =NULL; A PrivateImageView ImageView =NULL; at - 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); inButton.settext ("Combo Animation 1"); -Button.setonclicklistener ( This); to } + Public voidOnClick (View v) { -Animation Animation1 = animationutils.loadanimation ( This, R.anim.alpha); the imageview.startanimation (animation1); * FinalAnimation Animation2 = animationutils.loadanimation ( This, r.anim.translate); $Animation1.setanimationlistener (NewAnimationlistener () {Panax Notoginseng //called when the animation starts - Public voidOnanimationstart (Animation Animation) { the //TODO auto-generated Method Stub + A } the //called when the animation repeats + Public voidonanimationrepeat (Animation Animation) { - //TODO auto-generated Method Stub $ $ } - //called when the animation starts - Public voidonanimationend (Animation Animation) { the //TODO auto-generated Method Stub - imageview.startanimation (animation2);Wuyi } the }); - } Wu}
Here are just two types of animation to achieve the effect, in fact, we can be a variety, to see their own needs.
Animation changes in Android animation case 1