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 );}});