Package Com.example.animation;import Android.app.activity;import Android.os.bundle;import android.view.Menu;import Android.view.menuitem;import Android.view.view;import Android.view.animation.translateanimation;import Android.widget.imageview;import Android.widget.toast;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main);} public void Click (View view) {Toast.maketext (This, "click", Toast.length_short). Show ();} public void Move (view view) { float fromxdelta=0;float toxdelta=0;float fromydelta=0;float toydelta=200; translateanimation animation = new Translateanimation (Fromxdelta, Toxdelta, Fromydelta, Toydelta);/** * Time */animation . setduration (+); Animation.setfillafter (true); ImageView imageview= (ImageView) Findviewbyid (R.id.imageview); Imageview.startanimation (animation);} }
This is the general animation, and then the property animation
Difference: The general animation after the transformation is only the picture moved, the location of the view is not changed, however, the property animation view with the picture movement.
public void Move (view view) {ImageView imageview= (ImageView) Findviewbyid (R.id.imageview); Objectanimator.offloat ( ImageView, "Translationy", 0f,200f). Setduration (+). Start ();
Multiple animations at the same time
public void Move (view view) {ImageView imageview= (ImageView) Findviewbyid (R.id.imageview); Objectanimator.offloat ( ImageView, "Translationy", 0f,200f). Setduration (+). Start (); Objectanimator.offloat (ImageView, "Translationx", 0f , 200f). Setduration (+). Start (), Objectanimator.offloat (ImageView, "rotation", 0,360f). Setduration (+). Start () ;}
Google offers a variety of animations that save system resources while playing
public void Move (view view) {ImageView imageview= (ImageView) Findviewbyid (R.id.imageview); Propertyvaluesholder p1=propertyvaluesholder.offloat ("Rotation", 0,360f); Propertyvaluesholder p2=propertyvaluesholder.offloat ("Translationx", 0f,200f); Propertyvaluesholder p3=propertyvaluesholder.offloat ("Translationy", 0f,200f); O Bjectanimator.ofpropertyvaluesholder (ImageView, P1,P2,P3). Setduration (+). Start ();
At the same time, Google provides animatorset, allowing a variety of different animations to play according to user requirements, such as using Set.palytpgether () set.playsequentially ()
public void Move (view view) {ImageView imageview= (ImageView) Findviewbyid (R.id.imageview); Objectanimator animator1= Objectanimator.offloat (ImageView, "rotation", 0,360f); Objectanimator animator2=objectanimator.offloat (ImageView, " Translationx ", 0,200f); Objectanimator animator3=objectanimator.offloat (ImageView," Translationy ", 0,200f); Animatorset set=new Animatorset ();//set.playtogether (Animator1,animator2,animator3); Set.playSequentially ( ANIMATOR1,ANIMATOR2,ANIMATOR3); set.setduration (+); Set.start ();}
Android General animation animation and properties animation animator