Basic usage of property animation in Android

Source: Internet
Author: User

Basic usage of property animation in Android
In development, property animation is a very common function. Next I will record the basic usage of property animation for others to learn and gradually accumulate their own knowledge. Single animation effect:

// Create an animation object. The following parameters are: the target component of the animation effect, and the attributes to be modified (the get and set methods must be available ), the value of the subsequent three parameter write changes. ObjectAnimator animator = ObjectAnimator. ofFloat (textView, "TextSize", 15, 50, 15); // The animation process time is automatically and smoothly executed in the world. setDuration (6000); // animation starts animator. start ();

 

Combined animation effect:
// After (Animator anim) inserts an existing animation into the input animation and then executes the // after (long delay) operation. The latency of the existing animation is specified as milliseconds before the execution. // before (Animator anim) insert an existing animation to the input animation and execute // with (Animator anim) to execute the existing animation and the input animation at the same time. The following parameters are: the set attribute that needs to be changed for the target component of the animation effect (it must have the corresponding get and set methods). The subsequent three parameter write change processes correspond to numerical values. ObjectAnimator animator1 = ObjectAnimator. ofFloat (textView, "TextSize", 15, 50, 15); // The float init = textView of the target View is obtained each time. getRotation (); // rotation, same as ObjectAnimator animator2 = ObjectAnimator. ofFloat (textView, "rotation", init, init + 180f); // translation, same as ObjectAnimator animator3 = ObjectAnimator. ofFloat (textView, "TranslationX", curTranslationX,-500f, curTranslationX); // you can specify the animation class animation set AnimatorSet = new animatorSet (); // set how to combine the three animations with the animation set. play (animator2 ). with (animator1 ). after (animator3); // The animation process time, automatically and smoothly executed by the world. setDuration (6000); // The animation starts with animatorSet. start ();

 

Add a listener for the animation:
// Here is the listener added for the animation. You can select the method you want to implement, for example, animation execution completion, animation execution start, animation execution cancellation, and animation execution repetition. AnimatorSet. addListener (new AnimatorListenerAdapter () {// the content to be executed @ Override public void onAnimationEnd (Animator animation) {super. onAnimationEnd (animation );}});

 

 

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.