Directly on the code, there is not much written in advance, after the
Mainactivity
1 Packagecom.wuxianedu.animation;2 3 Importandroid.support.annotation.AnimRes;4 Importandroid.support.v7.app.AppCompatActivity;5 ImportAndroid.os.Bundle;6 ImportAndroid.view.View;7 Importandroid.view.animation.AlphaAnimation;8 Importandroid.view.animation.Animation;9 ImportAndroid.view.animation.AnimationSet;Ten Importandroid.view.animation.AnimationUtils; One Importandroid.view.animation.RotateAnimation; A Importandroid.view.animation.ScaleAnimation; - Importandroid.view.animation.TranslateAnimation; - ImportAndroid.widget.CompoundButton; the ImportAndroid.widget.ImageView; - ImportAndroid.widget.Switch; - - Public classMainactivityextendsAppcompatactivityImplementsView.onclicklistener { + - PrivateImageView Imgview; + Private Booleanischeched =true; A at @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); - - inSwitch Switch1 =(Switch) Findviewbyid (R.ID.SWITCH1); -Switch1.setoncheckedchangelistener (NewCompoundbutton.oncheckedchangelistener () { to @Override + Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) { -Mainactivity. This. ischeched =isChecked; the } * }); $ Panax Notoginseng -Findviewbyid (R.id.button). Setonclicklistener ( This); theFindviewbyid (R.id.button2). Setonclicklistener ( This); +Findviewbyid (R.id.button3). Setonclicklistener ( This); AFindviewbyid (R.id.button4). Setonclicklistener ( This); theFindviewbyid (R.ID.BUTTON5). Setonclicklistener ( This); +Imgview =(ImageView) Findviewbyid (R.id.imageview); - } $ $ - @Override - Public voidOnClick (View v) { the Switch(V.getid ()) { - CaseR.id.button://Gradient Transparent animationWuyi if(ischeched) { the Alphajava (); -}Else{ Wu Loadbyxml (r.anim.alpha_animation); - } About Break; $ CaseR.id.button2://Zoom Animation - //scaleanimation scaleanimation = new Scaleanimation (0,1,0,1); - //Scalejava (); - Loadbyxml (r.anim.scal_animation); A Break; + CaseR.id.button3://Displacement Animation the //Translatejava (); - Loadbyxml (r.anim.translate_animation); $ Break; the CaseR.id.button4://Rotate Animation the //Rotatejava (); the Loadbyxml (r.anim.rotate_animation); the Break; - CaseR.ID.BUTTON5://Animation Set inAnimationset Animationset =NewAnimationset (true); the the //Create three animations AboutRotateanimation rotateanimation =NewRotateanimation (0,360,animation.relative_to_self,0.5f, theanimation.relative_to_self,0.5f); theScaleanimation scaleanimation =NewScaleanimation (0,1,0,1,animation.relative_to_self,0.5f, theanimation.relative_to_self,0.5f); +Translateanimation translateanimation =NewTranslateanimation (0,800,0,800); - the //adding animations to an animation setBayi animationset.addanimation (rotateanimation); the animationset.addanimation (scaleanimation); the animationset.addanimation (translateanimation); - - //set the length of time theAnimationset.setduration (3000); the the //Start Animation the imgview.startanimation (animationset); - Break; the } the } the 94 /** the * Displacement Animation the */ the Private voidTranslatejava () {98Translateanimation translateanimation =NewTranslateanimation (0,800,0,800); AboutTranslateanimation.setduration (3000); - imgview.startanimation (translateanimation);101 }102 103 /**104 * Rotate Animation the */106 Private voidRotatejava () {107Rotateanimation rotateanimation =NewRotateanimation (0,360,animation.relative_to_self,0.5f,108animation.relative_to_self,0.5f);109Rotateanimation.setduration (3000); the imgview.startanimation (rotateanimation);111 } the 113 /** the * Zoom Animation the */ the Private voidScalejava () {117Scaleanimation scaleanimation =NewScaleanimation (0,1,0,1,animation.relative_to_self,0.5f,118animation.relative_to_self,0.5f);119Scaleanimation.setduration (3000); - imgview.startanimation (scaleanimation);121 }122 123 /**124 * Loading animations via XML the * @paramresId Animation resources, layout files126 */127 Private voidLoadbyxml (@AnimResintresId) { -Animation Animation = animationutils.loadanimation ( This, resId);129 imgview.startanimation (animation); the }131 the /**133 * Gradient Transparent animation134 */135 Private voidAlphajava () {136Alphaanimation alphaanimation =NewAlphaanimation (1,0);137Alphaanimation.setduration (3000);138 imgview.startanimation (alphaanimation);139 } $}
Android Learning notes-animation effects