How to solve the issue of attribute animation ofArgb version restrictions, attribute animation ofargb version

Source: Internet
Author: User

How to solve the issue of attribute animation ofArgb version restrictions, attribute animation ofargb version

Attribute animation ValueAnimator. ofArgb is incompatible when the Android version is earlier than 5.0, causing program crash. How can this problem be solved? This requires the knowledge of the User-Defined estimator.

 
if (Build.VERSION.SDK_INT < 21){ mGradientAnim = ValueAnimator.ofObject(new TextArgbEvaluator(), startColor, endColor); }else { mGradientAnim = ValueAnimator.ofArgb(startColor , endColor); }
 
Private class TextArgbEvaluator implements TypeEvaluator {// This code is the public Object evaluate (float fraction, Object startValue, Object endValue) {int startInt = (Integer) startValue derived from the source code; int startA = (startInt> 24) & 0xff; int startR = (startInt> 16) & 0xff; int startG = (startInt> 8) & 0xff; int startB = startInt & 0xff; int endInt = (Integer) endValue; int endA = (endInt> 24) & 0xff; int endR = (endInt> 16) & 0xff; int endG = (endInt> 8) & 0xff; int endB = endInt & 0xff; return (int) (startA + (int) (fraction * (endA-startA ))) <24) | (int) (startR + (int) (fraction * (endR-startR) <16) | (int) (startG + (int) (fraction * (endG-startG) <8) | (int) (startB + (int) (fraction * (endB-startB ))));}}

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.