Android feature animation for advanced elements

Source: Internet
Author: User
Tags final

Since Android3.0 has a lot of animation framework before, one of them is animation, but with the development of the Times and the enhancement of interaction requirements, animation limitations are becoming more and more obvious, such as: Anmiation animation can not respond to click events and so on. Therefore, after Android3.0, Google introduced a new animation framework--property animation (animator).

The most used in the animator framework is Animatorset and Objectanimator, with objectanimator for finer control, controlling only one attribute value of an object, Instead, use multiple objectanimator combinations to animatorset to form an animation. And Objectanimator can be automatically driven, you can call Setframedelay (Longframedelay) set the gap between animation frame time, adjust the frame rate, reduce the animation process of frequent draw interface, Without affecting the animation effect on the premise of reducing the CPU resource consumption.

Next, look at the most basic objectanimator in the attribute animation.

First look at the basic usage format:

      (View TV) {
        animator = objectanimator.offloat (TV,,);
        Animator.setduration ();
        Animator.start ();

TV is a control, "Alpha" is a string-formatted property value, in addition to this property value, there are

Translationy, Translationx : These two properties act as an increment to control where the view object is offset from the upper-left corner of the layout container
rotation, RotationX, RotationY: controls the View object around the fulcrum for 2D and 3D rotation.
ScaleX, ScaleY : Control view objects around the fulcrum for 2D scaling
Prvotx, Pivoty : Control controls around this point for scaling transform processing
x, y: Describes the final position of the View object in its container, its initial upper left corner coordinate and the cumulative value of the Translationy and Translationx values.
Alpha Control transparency

This is the use of a property for an object, and if there are multiple attributes, then use the Propertyvaluesholder

For example, now to implement a translation scaling animation effect, the specific approach is:

      () {
        Propertyvaluesholder pvh1 = Propertyvaluesholder.offloat (
                , f);

        Propertyvaluesholder pvh2 = Propertyvaluesholder.offloat (, F,
        Propertyvaluesholder Pvh3 = Propertyvaluesholder.offloat (, F,
        Objectanimator.ofpropertyvaluesholder (TV, PVH1, PVH2, Pvh3)
                . Setduration (). Start ();


In fact, the usage is similar to Animationset, at the same time, it is similar to the usage of animatorset that we are going to talk about later.

Next, take a look at another class that occupies an important place in the attribute animation--valueanimator

This class is actually quite powerful, even objectanimator inherited it. It doesn't animate, but it generates a lot of regular numbers, so we have this number, and of course we can do the animation, like the following usage:

      () {
        final valueanimator animator =valueanimator.offloat (,);
        Animator.settarget (TV);
        Animator.setduration (). Start ();
        Animator.addupdatelistener (Animatorupdatelistener () {

              (valueanimator arg0) {
                  = () Arg0.getanimatedvalue ();
                Viewgroup.layoutparams layoutparams = Layout.getlayoutparams ();
                Layoutparams.height = ();
                Layout.setlayoutparams (Layoutparams);

Here is through this write data, to constantly set the height of the view, to achieve an animation effect.

At the end of the Animatorset, as mentioned earlier, its usage and propertyvaluesholder are very similar, but the difference is that it can achieve multiple objects and multiple properties of the simultaneous animation effect, the approximate usage is as follows:

      Oneanimatorset () {
        objectanimator animator=objectanimator.offloat (TV,,);
        Objectanimator animator2=objectanimator.offloat (TV,,,,);
        Objectanimator animator3=objectanimator.offloat (TV,,,,  );
        Animatorset  =  animatorset ();
        . Setduration ();
        . Playtogether (ANIMATOR,ANIMATOR2,ANIMATOR3);
        Start ();

In attribute animation, animator is controlled by Playtogether (), with (), before, and so on, so that the sequence of animation playback is controlled precisely.

Today is just a simple understanding of the basic usage, I will be in the later learning, the introduction of the actual meaning of the animation effect. Thanks for reading.

Finally, thanks to the Xu Yisheng great God.

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: 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.