Android animator Animation

Source: Internet
Author: User
Animation animation is used to make the UI dynamic and stylish. There are two animation methods in Android:
One way is to make the animation TweenAnimation, that is, you define a start and end, and the middle part is obtained by the program operation. The other is frame-by-frame animation. FrameAnimation, that is, when a frame is connected and played, it becomes an animation.
Animation Effects: 1. move (translation) 2. transparency (alpha) 3. rotate (rotate) 4. scale: The following implementation is implemented by code (objectanimator) 1. Mobile (Translation)Main Code

AnimatorSet set = new AnimatorSet() ;            ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "translationX", -500f, 0f);anim.setDuration(2000);ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "translationX", 0f, -500f);anim3.setDuration(2000);ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "translationY", 0f, -500f);anim2.setDuration(2000);ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "translationY", -500f, 0f);anim4.setDuration(2000);AnimatorSet set3 = new AnimatorSet();set3.play(anim4).before(anim3) ;AnimatorSet set2 = new AnimatorSet();set2.play(anim2).before(set3) ;set.play(anim).before(set2);set.start();

Explanation: anim is to move from-500f to the current position (X axis); anim3 is to move from the current position to-500f (X axis ); anim2 is the position from the current position-500f (Y axis); anim 4 is the position from-500f to the current position (Y axis );

AnimatorSet set3 = new AnimatorSet();set3.play(anim4).before(anim3) ;AnimatorSet set2 = new AnimatorSet();set2.play(anim2).before(set3) ;set.play(anim).before(set2);set.start();

This aims to move the target view back and forth, where to start, and finally return to the starting position.

2. Transparency (alpha)
Main Code
AnimatorSet set = new AnimatorSet() ;ObjectAnimator anim = ObjectAnimator.ofFloat(phone, "alpha", 1f, 0f);anim.setDuration(2000);ObjectAnimator anim2 = ObjectAnimator.ofFloat(phone, "alpha", 0f, 1f);anim2.setDuration(2000);set.play(anim).before(anim2) ;set.start();

Explanation: anim is visible to invisible;
Anim is invisible;3. Rotate)Main Code

AnimatorSet set = new AnimatorSet() ;            ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "rotationX", 0f, 180f);anim.setDuration(2000);ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "rotationX", 180f, 0f);anim2.setDuration(2000);ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "rotationY", 0f, 180f);anim3.setDuration(2000);ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "rotationY", 180f, 0f);anim4.setDuration(2000);set.play(anim).before(anim2);set.play(anim3).before(anim4) ;set.start();
Explanation: anim changes from 0 degrees to 180 degrees (X axis)
Anim2 from 180 degrees to 0 degrees (X axis) anim3 from 0 degrees to 180 degrees (Y axis) anim4 from 180 degrees to 0 degrees (Y axis)
set.play(anim).before(anim2);set.play(anim3).before(anim4) ;

In this way, both X and Y are rotated at the same time.

4. Scale)
Main Code
AnimatorSet set = new AnimatorSet() ;            ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "scaleX", 1f);anim.setDuration(1000);ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "scaleX", 0.5f);anim2.setDuration(1000);ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "scaleY", 1f);anim3.setDuration(1000);ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "scaleY", 0.5f);anim4.setDuration(1000);ObjectAnimator anim5 = ObjectAnimator .ofFloat(phone, "scaleX", 0.5f);anim5.setDuration(1000);ObjectAnimator anim6 = ObjectAnimator .ofFloat(phone, "scaleX",  1f);anim6.setDuration(1000);ObjectAnimator anim7 = ObjectAnimator .ofFloat(phone, "scaleY",0.5f);anim7.setDuration(1000);ObjectAnimator anim8 = ObjectAnimator .ofFloat(phone, "scaleY",  1f);anim8.setDuration(1000);AnimatorSet set3 = new AnimatorSet() ; set3.play(anim5).before(anim6);AnimatorSet set2 = new AnimatorSet() ;  set2.play(anim2).before(set3) ; AnimatorSet set4 = new AnimatorSet() ;  set4.play(anim7).before(anim8) ;AnimatorSet set5 = new AnimatorSet() ;  set5.play(anim4).before(set4);set.play(anim).before(set2);set.play(anim3).before(set5) ;set.start();
Explanation: anim starts from the original size (X axis)
Anim2 scales to the original 1/2 (X axis) anim3 from the original size (Y axis)
Anim4 scales to the original 1/2 (Y axis)
Anim5 is enlarged from the original 1/2 (X axis)
Anim6 zoom in to the original size (X axis)
Anim7 is enlarged from the original 1/2 (Y axis)
Anim8 zoom in to the original size (Y axis)
Code: http://download.csdn.net/detail/luhuajcdd/5191812

 

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.