Android Animations: Motion Tweens (Tween animations)

Source: Internet
Author: User

The principle of tween animation in Android: animating the image by changing the content of the view (translation, zooming, rotation, transparency). The definition of animation effect can be done using XML or coding, and today it is simple to use code to implement the tween animation in four ways. There are four animation classes for each of the four animations:

Gradient Transparency Animation effect

Alphaanimation

Gradient Size Zoom animation effect

Scaleanimation

Picture Position move Animation effect

Translateanimation

Picture Rotation animation effect

Rotateanimation

1: Pan operation

/**translateanimation (float fromxdelta, float toxdelta,
Float Fromydelta, float toydelta)
The Fromxdelta parameter is the moving position on the x-coordinate at the start of the animation
The Toxdelta parameter is the moving position on the x-coordinate at the end of the animation
The Fromydelta parameter is the moving position of the y-coordinate at the start of the animation
parameter Toydelta is the moving position on the y-coordinate at the end of the animation */

animationtranslateanimation=New translateanimation (0, 100, 0, 0);

/** animation duration (in milliseconds) *,

Translateanimation.setduration (3000);

/** Animation Insert */

Translateanimation.setinterpolator (this, Android. R.anim. cycle_interpolator);

/** set the current position after the animation has ended */

Translateanimation.setfillafter (true);

Aminationview.startanimation (translateanimation);/**aminationview refers to the view*/of the animation to be realized

2 scaling operation

     /**scaleanimation (float FromX, float ToX, Float FromY, float toY,
       int Pivotxtype, float pivotxvalue, int pivotytype, float pivotyvalue);
  first parameter FROMX is the scaling dimension on the x-coordinate at the start of the animation    0.0 means shrink to no
  second parameter tox to stretch dimensions at end of animation at x-coordinate    1.0 indicates normal non-scaling
  The third parameter fromy the scaling size    value on the y-coordinate at the start of the animation is less than 1.0 to shrink the
  fourth parameter toy to the end of the animation when the scaling size     value greater than 1.0 on the y-coordinate is magnified */

/** defining scaled animations */

animationscaleanimation=New scaleanimation (0.5f, 1.0f,1.0f, 1.0f);

Scaleanimation.setduration (2000);

Scaleanimation.setfillafter (true);

Scaleanimation.setrepeatcount (3);

Aminationview. startanimation (scaleanimation); /**aminationview refers to the view*/to achieve animation


3 rotation operation

/**rotateanimation (float fromdegrees, float todegrees,
int Pivotxtype, float pivotxvalue, int pivotytype, float pivotyvalue)
The first parameter, fromdegrees, is the angle of rotation at the start of the animation. This angle is currently 0 and 360, and setting other values jumps first to the position of the angle and then by the value of from-to: Negative then forward, regular reverse
the second parameter todegrees the angle to which the animation is rotated
The third parameter Pivotxtype for the animation on the x-axis relative to the object position type
The fourth parameter, Pivotxvalue, is the start position of the animation relative to the object's x-coordinate, which is the origin of the original position, that is, if set to 20%p, the 20% displacement of the parent control is moved to the right, and a negative number moves to the left.
The fifth parameter Pivotxtype for the animation on the y-axis relative to the object position type
The sixth parameter, Pivotyvalue, is the start position of the animation relative to the object's y-coordinate, which is the origin of the original position, as if it were set to 20%p, move the parent control's 20% displacement downward, or the negative number to move up .

animationrotateanimation=New rotateanimation (0, 45);

Rotateanimation.setduration (3000);

Rotateanimation.setfillafter (true);

Aminationview. startanimation (rotateanimation); /**aminationview refers to the view*/to achieve animation

4 Transparency Change operation

/**alphaanimation (float fromalpha, float toalpha)
The first parameter, Fromalpha, is full transparency when the animation starts at 0.0.
The second parameter, Toalpha, is at the end of the animation when Transparency 1.0 is completely non-transparent */

animationalphaanimation=New alphaanimation (1, (float) 0.1);

Alphaanimation.setduration (3000);//Set animation duration to 3 seconds

Alphaanimation.setfillafter (true);//sets the current position at the end of the animation (that is, does not return to the position before the animation starts)

Aminationview. startanimation (alphaanimation); /**aminationview refers to the view*/to achieve animation


Android Animations: Motion Tweens (Tween animations)

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.