A tentative study of animation (II.)

Source: Internet
Author: User

alphaanimation is a transparency transform animation. It is a subclass of animation, animation is too big, after the next, first look at alphaanimation.

First, Alphaanimation has two attributes:

    Private float Mfromalpha;     Private float Mtoalpha;

See from Mfromalpha change to Mtoalpha. In fact, Alphaanimation's construction method is to set these two functions.

Second, the construction method of Alphaanimation:

1)

    /*** Constructor used when an alphaanimation are loaded from a resource. *      * @paramContext Application Context to use *@paramattrs Attribute set from which to read values*/     Publicalphaanimation (Context context, AttributeSet attrs) {Super(context, attrs); TypedArray a=context.obtainstyledattributes (Attrs, com.android.internal.r.styleable.alphaanimation); Mfromalpha= A.getfloat (Com.android.internal.r.styleable.alphaanimation_fromalpha, 1.0f); Mtoalpha= A.getfloat (Com.android.internal.r.styleable.alphaanimation_toalpha, 1.0f);    A.recycle (); }

This constructor has two input parameters, one is the context, and the other is the set parameter of the component. This setting parameter comes from the configuration of the XML file, and then uses the method inside the Typedarray to take out the parameters set in the XML and assigns values to the attributes. As you can see, if I do not configure Xml,mfromalpha and Mtoalpha will take the default value of 1.0f, the equivalent of a new animation without any changes.

2)

    /**      * Constructor to building a alphaanimation from code     *      @param  fromalpha Star Ting Alpha value for the animation, where 1.0 means     *        fully opaque and 0.0 means fully transparent.      @param Toalpha ending alpha value for the animation.      */     Public Alphaanimation (floatfloat  toalpha) {        = fromalpha;         = toalpha;    }

This is another way to construct alphaanimation. This is easier to understand, which is to assign values directly to Mfromalpha and Mtoalpha.

Third, other methods of alphaanimation.

1,applytransformation:

    /**      * Changes the Alphaproperty of the supplied {@link  Transformation}     * /    @Override     protected void applytransformation (float  interpolatedtime, transformation t) {          Finalfloat alpha = mfromalpha;         + ((mtoalpha-alpha) * interpolatedtime));    }

Visible applytransformation () method is the implementation of the animation, the system will be a relatively high frequency to call this method, I test the frequency of the call is about 40+fps.

We can inherit the alphaanimation class and rewrite the applytransformation () method, if the animation is a function of the horizontal axis for the time, the vertical is the transparency, by default this function is a straight line, We can set the calculation of the mapping of the public test. The system takes dozens of interpolatedtime values per second, and we can list a formula to calculate the transparency of each interpolatedtime mapping.

It's too late for the pit to dig here first.

A tentative study of animation (II.)

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.