Android Animation review: Zoom animation, pan animation, rotate animation and transparency animation

Source: Internet
Author: User
Tags relative

Now is the afternoon, I am still at work, the work is done, is testing, suddenly feel very confused, work for a year, still the same as the old, think of these can not help but to suck a cold sweat. So seize the time to look at my blog, update the content, sometimes do not force themselves, never know what the limits of their own. Today is a very basic and basic knowledge: animation. Animation is mainly divided into four kinds. 1. Zoom animation (scaleanimation); 2. Translation animation (translateanimation); 3. Rotating animation (rotateanimation); 4. Transparency (alphaanimation); In fact, there is another, called the animation set, now put a place here first. Next, I'll talk about how to implement the animation in Java code. See Zoom Animation First:

      (ImageView IV) {
        scaleanimation animation;
        Animation =  Scaleanimation (,,,, animation.relative_to_self,
                F, animation.relative_to_self, f);
        Animation.setduration ();
        Animation.setfillafter ();
        Iv.startanimation (animation);
    }
See the code inside, first of all this is a private method, passed a ImageView object, so it is obvious that this is to achieve the zoom effect of the picture. Focus on the three construction methods of Scaleanimation:
1.ScaleAnimation (FromX, ToX, FromY, ToY); 2.ScaleAnimation (FromX, ToX, FromY, ToY, Pivotx, Pivoty
);
3. Scaleanimation (FromX, ToX, FromY, ToY, Pivotxtype, Pivotxvalue, Pivotytype, Pivotyvalue)
The first is really obvious, from the angle of horizontal and vertical scaling, the default origin is the upper-left corner of the current ImageView control. The
second one has two more parameters than the other, and these two parameters are the one that allows us to define the origin. The
third one seems richer, and it is not difficult to understand the word. The first four are similar, focus on the following four, the first is pivotxtype, this refers to the origin of the relative X type, commonly used is animation.relative_to_self,pivotxvalue refers to the origin of the value, general, 0.5 refers to the original point, The following two arguments are followed by analogy.

So, a zoom animation is done.


Next, take a look at the translation animation:
      (ImageView IV) {
        translateanimation animation;
        Animation =  Translateanimation (,, animation.relative_to_self,
                animation.relative_to_self);
        Animation.setduration ();
        Animation.setfillafter ();
        Iv.startanimation (animation);
    }
Again, let's look at how it is structured.
1.TranslateAnimation (Fromxdelta, Toxdelta, Fromydelta, Toydelta);
2.TranslateAnimation (Fromxtype, Fromxvalue, Toxtype, Toxvalue, Fromytype, Fromyvalue, Toytype, Toyvalue);

Let's analyze the specific meaning of this parameter:

Float Fromxdelta: This parameter indicates the difference between the point at which the animation begins and the current view x coordinate;

Float Toxdelta, this parameter indicates the difference between the point at which the animation ends and the current view x coordinates;

Float Toxdelta, this parameter indicates the difference between the point at which the animation ends and the current view x coordinates;

float Toydelta) This parameter represents the difference between the point at which the animation begins and the current view y coordinate;

If the view is at a (x,y) point then the animation is moving from point B (X+fromxdelta, Y+fromydelta) to point C (X+toxdelta,y+toydelta).

The second method of construction

Fromxtype: The first parameter is the reference to the value in the x-axis direction (Animation.absolute,animation.relative_to_self,or animation.relative_to_parent);

Fromxvalue: The second parameter is the starting value of the first parameter type;

Toxtype,toxvalue: The third parameter and the fourth parameter is the end point reference and corresponding value of the x axis direction;

The following four parameters are not explained. If you select all Animation.absolute, it is actually the second constructor.

  Take the x axis as an example to describe the relationship between the reference and the corresponding value:

  If the selection reference is Animation.absolute, then the corresponding value should be the specific coordinate value, such as 100 to 300, which refers to the absolute screen pixel unit

  If you choose to refer to animation.relative_to_self or animation.relative_to_parent as relative to yourself or to a parent control, the corresponding value should be interpreted as relative to itself or to several times or as much as the parent control. The multiple test parameters will be clear.

Let's take a look at the spin animation:

      (ImageView IV) {
        rotateanimation animation;
        Animation =  Rotateanimation (,, animation.relative_to_self,
                F, animation.relative_to_self, f);
        Animation.setduration ();
        Animation.setfillafter ();
        Iv.startanimation (animation);
    }

First, analyze how it is constructed:

1.RotateAnimation (Fromdegrees, todegrees);

2.RotateAnimation (Fromdegrees, Todegrees, Pivotx, Pivoty);

3. Rotateanimation (Fromdegrees, Todegrees, Pivotxtype, Pivotxvalue, Pivotytype, Pivotyvalue).

In this area:

Fromdegrees refers to from what angle, todegrees refers to at what angle end. The origin of the first argument is the upper-left corner of the control.

The rest of the zoom animation has been involved, it is not in the fat.

Finally look at the transparency animation:

      (ImageView IV) {
        alphaanimation animation;
        Animation =  Alphaanimation (,);
        Animation.setduration ();
        Animation.setfillafter ();
        Iv.startanimation (animation);
    }

This one is simpler and has only one important construction method.

It's also obvious here, from what state to what state, the smallest is-1 the largest is 1

All right, so far, the effect of Java code implementing control animations is over, and next time we'll talk about how to set up animations in XML and how to reference them in Java code.

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.