Android Animation effects Demo

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.