Packagecom.example.administrator.mystudent.PropertyAnimation;ImportAndroid.animation.AnimatorSet;ImportAndroid.animation.ObjectAnimator;ImportAndroid.animation.PropertyValuesHolder;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.animation.AnimationSet;ImportAndroid.view.animation.BounceInterpolator;Importandroid.view.animation.TranslateAnimation;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView;ImportCOM.EXAMPLE.ADMINISTRATOR.MYSTUDENT.R;/*** Created by Hyang on 2016/8/26. * Attribute Animation learning*/ Public classPropertyanimationactivityextendsandroid.app.activity{PrivateImageView img; Privatebutton button; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_property_animation); IMG=(ImageView) Findviewbyid (r.id.iv_img); Button=(Button) Findviewbyid (R.ID.BTN); Button.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {//SetAnimation1 (); //SetAnimation2 (); //SetAnimation3 ();SetAnimation4 (); } }); } /*** Tween Animation*/ Private voidSetAnimation1 () {translateanimation animation=NewTranslateanimation (0,200,0,0); Animation.setduration (3000); //Animation.setfillafter (true);//stay where the animation is doneimg.startanimation (animation); } /*** Property Animation * Way 1*/ Private voidSetAnimation2 () {objectanimator.offloat (IMG,"Translationx", 0,200f). Setduration (3000). Start (); Objectanimator.offloat (IMG,"Rotation", 0,360f). Setduration (3000). Start (); } /*** Property Animation * Way 2*/ Private voidSetAnimation3 () {propertyvaluesholder P1=propertyvaluesholder.offloat ("Translationx", 0, 200f); Propertyvaluesholder P2=propertyvaluesholder.offloat ("Rotation", 0, 360f); Objectanimator.ofpropertyvaluesholder (IMG,P1,P2). Setduration (3000). Start (); } /*** Property Animation * Mode 3 * animation sequence*/ Private voidSetAnimation4 () {objectanimator ObjectAnimator1=objectanimator.offloat (IMG, "Translationx", 0, 200f); Objectanimator ObjectAnimator2=objectanimator.offloat (IMG, "rotation", 0, 360f); //create several animation effects from Android (in Android Apidemo)Objectanimator1.setinterpolator (Newbounceinterpolator ()); Animatorset Animatorset=NewAnimatorset (); //animatorset.playsequentially (OBJECTANIMATOR1,OBJECTANIMATOR2); //Play animations sequentiallyAnimatorset.play (ObjectAnimator1). After (ObjectAnimator2); Animatorset.setduration (3000); Animatorset.start (); }}
Android Properties Animation