Android--animation

Source: Internet
Author: User
Tags repetition

Animations in Android:

Category: Tweenanimation (motion Tween) and frameanimation (frame animation).

    1. Tweenanimation, it is a kind of gradual effect to produce animation effect by changing the image.

      Alphaanimation: transparency Gradient;

      Scaleanimation: Size scaling;

      Translateanimation: Mobile

      Rotateanimation: Rotate

    2. Frameanimation: Sequential playback of pre-done images is a conversion animation;

Second, the attribute introduction:

    1. Tweenanimation Common attributes:

Android:duration [Long]: the duration of the animation;

Android:fillafter [Boolean]: The view stops at the end of the animation, but the real position is still the given position in the layout;

Android:fillbefore[boolean]: The view stops at the beginning of the animation position;

Android:interpolator: Specifies an animated plug-in that is commonly used with the following inserts:

Accelerater_decelerate_interpolator: Acceleration-deceleration animation insert

Accelerater_interpolator: accelerating the animation insert;

Deceleratr_interpolator: deceleration animation insert;

Android:repeatcount[int]: Animation repetition, 1 means infinite loop;

Android:repeatmode[int]: Defines the behavior of the animation repetition, 1, starting from the starting point, 2, from the end position to start the opposite execution;

Android:startoffset[long]: The interval between animations and the next animation from the time the last animation was stopped;

Android:zadjustment[int]: Defines the change in Z order of the animation, 0: Keep z order unchanged, 1: Keep at the top;-1 keep at the bottom; Pending verification)

1.1 Alphaanimation

Defined in XML

<!--<alpha android:fromalpha= "" At the beginning of transparency, 0.0-1.0--><!--android:toalpha= "" At the end of the transparency 0.0-1.0--><!-- Android:duration= "" Animation duration/>--

The code defines:

Fromalpha: Transparency at the beginning, Toalpha: Transparency at the end alphaanimation alpha = new Alphaanimation (Fromalpha, Toalpha);// Sets the duration of the animation alpha.setduration (Durationmillis);

1.2 Scaleanimation

Xml

<!--<scale--><!--android:fromxscale= "" The scaling dimensions on the x-coordinate at the start of the animation--><!--android:toxscale= "" The x-coordinate at the end of the animation     Shrink size--><!--android:fromyscale= The scaling dimensions on the y-axis at the start of the animation--><!--android:toyscale= "" Stretch dimensions on the y-axis at the end of the animation--><!-- Android:pivotx= the start position of the animation relative to the object's x-coordinate--><!--android:pivoty= "" animation relative to the beginning of the object's y-coordinate--><!--/>-

In your code

Scaleanimation scale = new Scaleanimation (FromX, ToX, FromY, ToY);

1.3 translateanimation

Xml

<translate android:fromxdelta= "0%"//x axis start position android:pivotx= "0%"//animation relative to the beginning of object X coordinate android:pivoty= " 0% "//animation is relative to the start position of the object y-coordinate android:toxdelta=" 30% "//x axis end position android:fromydelta=" 0% "//y axis start position Android:toydel Ta= "0%"//y axis end position android:duration= "10000"/>

In the code:

Translateanimation anim = new Translateanimation (Fromxdelta, Toxdelta, Fromydelta, Toydelta)

1.4 Rotateanimation

Xml

<!--<rotate--<!--android:fromdegrees= "" Angle of the object at the start of the animation-<!--android:todegrees= "" The angle of the object rotation at the end of the animation -<!--angle is negative to rotate counterclockwise, the angle is positive to rotate clockwise--<!--android:pivotx= "" animation is relative to the start of object x coordinates--<!--android:p Ivoty= the start of the animation relative to the y-coordinate of the object-<!--android:duration= "" Animation run time/>

Code:

Scaleanimation anim = new Scaleanimation (FromX, ToX, FromY, ToY)

2.xml defines the use of animations in activity:

Animation Animation = (Animation) animationutils.loadanimation (Mainactivity.this, r.anim.animation);

3. Use of the Interpolator

Interpolator Object Resource ID Functional Role
Acceleratedecelerateinterpolator @android: Anim/accelerate_decelerate_interpolator Accelerate and decelerate first.
Accelerateinterpolator @android: Anim/accelerate_interpolator Accelerated
Anticipateinterpolator @android: Anim/anticipate_interpolator Take a small step back and speed it up.
Anticipateovershootinterpolator @android: Anim/anticipate_overshoot_interpolator A small step beyond the finish line on the last, and then back to the end.
Bounceinterpolator @android: Anim/bounce_interpolator Final stage Pinball effect
Cycleinterpolator @android: Anim/cycle_interpolator Periodic motion
Decelerateinterpolator @android: Anim/decelerate_interpolator Slowdown
Linearinterpolator @android: Anim/linear_interpolator Uniform
Overshootinterpolator @android: Anim/overshoot_interpolator Get to the finish line quickly and go beyond one step to the end

4.FrameAnimation: Frame animation

Add pictures and play them in the order of adding pictures;

Animationdrawable anima = new Animationdrawable () Anima.addframe (Drawable1, Duration1); Anima.addframe (Drawable2, Duration2); Anima.addframe (Drawable3, Duration3); Anima.addframe (Drawable4, Duration4); View.setbackgrouddrawable ( ANIMA);


Android--animation

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.