Android General animation animation and properties animation animator

Source: Internet
Author: User

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

Related Article

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.