Android property animation memo nineold

Source: Internet
Author: User

Android property animation memo nineold
Occasionally, animations are used for project development. It is too troublesome to copy the previous code every time, but I can't remember it, so I have to write it here.

ObjectAnimator. ofFloat (view, "translationX", 0, 50,-50, 0 ). setDuration (duration ). start (); // shift ObjectAnimator. ofFloat (view, "translationY", 0, 50,-50, 0 ). setDuration (duration ). start (); ObjectAnimator. ofFloat (view, "scaleX", 1, 2, 1 ). setDuration (duration ). start (); // scale ObjectAnimator. ofFloat (view, "scaleY", 1, 2, 1 ). setDuration (duration ). start (); ObjectAnimator. ofFloat (view, "alpha", 1, 0, 1 ). setDuration (duration ). start (); // transparency ObjectAnimator. ofFloat (view, "rotationX", 0,180, 0 ). setDuration (duration ). start (); // flip ObjectAnimator. ofFloat (view, "rotationY", 0,180, 0 ). setDuration (duration ). start (); ObjectAnimator. ofFloat (view, "rotation", 0,180, 0 ). setDuration (duration ). start (); // rotate ViewHelper. setmediatx (view, view. getWidth ()/2f); // sets the animation base point ViewHelper. setpolicty (view, view. getHeight ()/2f );

 

The above is a commonly used nineold, but occasionally encounter combinations, which is easier to use.
AnimatorSet animator = new AnimatorSet();        animator.playTogether(            ObjectAnimator.ofFloat(image, "rotation", 0, 1080),            ObjectAnimator.ofFloat(image, "translationX", 0, 180),            ObjectAnimator.ofFloat(image, "translationY", 0, -180),            ObjectAnimator.ofFloat(image, "scaleX", 1, 0),            ObjectAnimator.ofFloat(image, "scaleY", 1, 0)            ObjectAnimator.ofFloat(image, "alpha", 1, 0.25f, 1)        );        animator.setDuration(5 * 1000).start();

 

Today, when I add a product to the shopping cart, the product image is rotated and scaled out to the specified position of the shopping cart icon. It is very troublesome to use Attribute animation. If the animation execution order is messy, there will be problems with the displacement trajectory. probably record it to avoid forgetting
Int [] endLocation = new int [2]; topSpcart. getLocationInWindow (endLocation); // shopCart is the shopping cart // calculates the displacement int endX = endLocation [0]-startLocation [0]; // X coordinate int endY = endLocation [1]-startLocation [1]; // y coordinate RotateAnimation rotateAnimation = new RotateAnimation (0, 1080, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); ScaleAnimation scaleAnimation = new ScaleAnimation (1, 0, 1, 0, Animation. RELATIVE_TO_SELF, 0, Animation. RELATIVE_TO_SELF, 0); TranslateAnimation translateAnimation = new TranslateAnimation (0, endX, 0, endY); // translateAnimation. setInterpolator (new LinearInterpolator (); // animation accelerator // translateAnimation. setInterpolator (new AccelerateInterpolator (); // translateAnimation. setRepeatCount (0); // number of repeated animation executions // translateAnimation. setFillAfter (true); // The animation ends at the original position, and the animation ends at the animation set = new AnimationSet (false); set. setFillAfter (true); set. addAnimation (rotateAnimation); // rotate set. addAnimation (scaleAnimation); // scale the set. addAnimation (translateAnimation); // displacement set. setDuration (1000); // view the animation execution time. startAnimation (set); // set the animation listening event. setAnimationListener (new AnimationListener () {// Animation start @ Override public void onAnimationStart (animation Animation) {}@ Override public void onAnimationRepeat (animation Animation) {}// Animation end @ Override public void onAnimationEnd (animation 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.