The first: Translateanimation Animation effect Demo:
public void Move (view view) {//Traditional animation effect translateanimation Animation=new translateanimation (0, 500, 0, 0);// Time Animation.setduration (500);//Set the position after the move does not recover Animation.setfillafter (true); ImageButton img= (ImageButton) Findviewbyid (R.ID.IMG); TextView tv= (TextView) Findviewbyid (R.id.lab);//Set animation effect control img.startanimation (animation); Tv.startanimation ( Animation); Toast.maketext (This, "Move Time", Toast.length_short). Show ();
XML Configuration button Time
<button android:gravity= "center" android:layout_margintop= "500sp" android:layout_marginstart= " 30SP " android:layout_marginleft=" 30sp " android:layout_width=" wrap_content " android:layout_height=" Wrap_content " android:text=" move button " android:id=" @+id/btn " android:onclick=" Move "
Use Objectanimator----------with-------------
-------------Use Objectanimator----------
Objectanimator animator=new objectanimator ();
Animator.offloat (IMG, "Translationy", 0,100). Setduration (+). Start ();
if (flag)
{
Animator.offloat (IMG, "Y", 0,300). Setduration (+). Start ();
Animator.offloat (IMG, "X", 0,300). Setduration (+). Start ();
Animator.offloat (IMG, "rotation", 0,360). Setduration (+). Start ();
Flag=false;
}
Else
{
Animator.offloat (IMG, "Y", 300,0). Setduration (+). Start ();
Animator.offloat (IMG, "X", 300,0). Setduration (+). Start ();
Animator.offloat (IMG, "rotation", 3600,0). Setduration (+). Start ();
Flag=true;
}
Use of Propertyvaluesholder objects
/** * Unlike above is code optimized */public void Proptevalueholderdemo () {ImageButton img= (ImageButton) Findviewbyid (r.id.img); Propertyvaluesholder pro1=propertyvaluesholder.offloat ("Rotation", 0,360f); Propertyvaluesholder pro2=propertyvaluesholder.offloat ("x", 0,300); Propertyvaluesholder pro3=propertyvaluesholder.offloat ("Y", 0,300); Objectanimator.ofpropertyvaluesholder (IMG, PRO1,PRO2,PRO3). Setduration (+). Start ();
/** * Animate effect */public void Playsequentiallydemo () {ImageButton img= (ImageButton) Findviewbyid (r.id.img) in sequence; O Bjectanimator animator1=objectanimator.offloat ("img", "X", 0,360f); Objectanimator animator2=objectanimator.offloat ("img", "Y", 0,360f); Animatorset set=new Animatorset (); set.playsequentially (Animator1,animator2); set.setduration (+); Set.start ();}
Android Animation effects Demo