Objectanimator of Android Properties animation

Source: Internet
Author: User

I believe for Android beginners, for Android animation effect must be very interested, today for everyone to summarize the property animation case just learned.

First, like the General Android application, we first build a project, in order to facilitate, our layout file only add a ImageView and button buttons, the code is as follows:

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent"Android:layout_height= "Match_parent" android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Android:paddingbottom= "@dimen/activity_vertical_margin" tools:context= ". Mainactivity "> <ImageView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/imageview"Android:layout_alignparenttop= "true"Android:layout_alignparentleft= "true"Android:layout_alignparentstart= "true"android:src= "@drawable/ic_launcher"Android:onclick= "Imgclick"/> <Button android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Animation"Android:id= "@+id/button"Android:layout_alignparentbottom= "true"Android:layout_centerhorizontal= "true"Android:layout_marginbottom= "86DP"Android:onclick= "ButtonClick"/></relativelayout>

Here is our action, in order to facilitate everyone to learn, I will share the code as follows:

 Public classMainactivityextendsActivity { PublicImageView ImageView;  Publicbutton button; Static intx = 0, xx = 0, y = 0, yy = 0; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); ImageView=(ImageView) Findviewbyid (R.id.imageview); Button=(Button) Findviewbyid (R.id.button); }     Public voidImgclick (view view) {Toast.maketext ( This, "ImageView", Toast.length_short). Show (); }     Public voidButtonClick (view view) {//xx + =;//translateanimation ta = new Translateanimation (x, xx, y, yy);//set offset displacement of an animation//x + =;//ta.setduration (+);//set the duration of the animation//Ta.setfillafter (true);//set the end of the animation to stay in that position//imageview.startanimation (TA); //Property Animation calls the Start () method after an asynchronous operation//objectanimator.offloat (ImageView, "Translationx", 0F, 360F). Setduration (+). Start ();//x-Axis translational rotation//objectanimator.offloat (ImageView, "Translationy", 0F, 360F). Setduration (+). Start ();//y-Axis translational rotation//objectanimator.offloat (ImageView, "rotation", 0F, 360F). Setduration (+). Start ();//360 degree rotation//Synchronous Animation Design//propertyvaluesholder p1 = propertyvaluesholder.offloat ("Translationx", 0, 360F);//propertyvaluesholder P2 = propertyvaluesholder.offloat ("Translationy", 0, 360F);//Propertyvaluesholder p3 = propertyvaluesholder.offloat ("Rotation", 0, 360F);//Objectanimator.ofpropertyvaluesholder (ImageView, p1, p2, p3). Setduration (+). Start (); //Design Multiple Property animations for synchronous execution with AnimatiorsetObjectanimator Animator1 = objectanimator.offloat (ImageView, "Translationx", 0F, 360F);//x-Axis translational rotationObjectanimator Animator2 = objectanimator.offloat (ImageView, "Translationy", 0F, 360F);//y-Axis translational rotationObjectanimator Animator3 = objectanimator.offloat (ImageView, "rotation", 0F, 360F);//360 degree rotationAnimatorset set =NewAnimatorset (); //set.playsequentially (Animator1, Animator2, Animator3);//Step into the execution of//Set.playtogether (Animator1, Animator2, Animator3);//Synchronous Execution//execution order control of property animations//the animation Animator2 and Animator3 are performed synchronously before performing the Animator1Set.play (Animator3). with (Animator1);        Set.play (Animator2). After (Animator3); Set.setduration (1000);    Set.start (); }}

For the key position, I have made a detailed comment, you can copy to your own project to test, I believe you can master the knowledge of property animation in Android.

Objectanimator of Android Properties animation

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.