Android and androidsdk
Interpolator is used to modify the animation effect, define the animation change rate, and enable the existing animation effects such as accelerated, decelerated, repeated, and bounced.
| AccelerateDecelerateInterpolator |
The speed changes slowly at the beginning and end of the animation, accelerating at the center |
| AccelerateInterpolator |
Speed changes are slow at the beginning of the animation and acceleration starts. |
| AnticipateInterpolator |
At the beginning, move backward and forward. |
| AnticipateOvershootInterpolator |
Returns the final value after a value is pushed forward at the beginning. |
| BounceInterpolator |
When the animation ends |
| CycleInterpolator |
Specifies the number of times the animation is played cyclically, and the speed changes along the sine curve. |
| DecelerateInterpolator |
Fast and slow at the beginning of the animation |
| LinearInterpolator |
Change at constant rate |
| OvershootInterpolator |
Return to the original position after throwing a value forward |
If android-defined interpolators do not match your performance, you can also customize interpolators.
Interpolator Interface
Package android. animation;/*** the time interpolation device defines the rate of change of an animation. * This allows an animation to move non-linear tracks, such as acceleration and deceleration. */Public interface TimeInterpolator {/*** ing the scores of the time consumed by the animation to a score that indicates interpolation. * Then, the interpolation value is multiplied by the animation change value to export the animation changes of the past animation time. ** @ Param input a value ranging from 0 to 1.0 indicates the value of the current animation point, and 0 indicates the beginning. 1 indicates the end * @ return interpolation. Its value can be greater than 1 to exceed the target value, or smaller than 0 to break the bottom line. */Float getInterpolation (float input );}
TimeInterpolator is a class called Interpolator before Android API11.
Package android. view. animation; import android. animation. TimeInterpolator;/*** an interpolation tool that defines the animation change rate. * It allows acceleration, deceleration, repetition, and other animation effects on basic (such as transparency, scaling, translation, and rotation) */public interface Interpolator extends TimeInterpolator {// A new interface, timeInterpolator, was introduced for the new android. animation // package. this older Interpolator interface extends TimeInterpolator so that users of // the new Animator-based animations can use either the old Interpolator implementations or/new classes that implement TimeInterpolator directly .}AccelerateInterpolator
/*** An interpolation tool that starts slowly and continues to accelerate. */Public class AccelerateInterpolator implements Interpolator {private final float mFactor; private final double mDoubleFactor; public AccelerateInterpolator () {mFactor = 1.0f; mDoubleFactor = 2.0 ;} /***** @ param factor * the animation speed. Setting factor to 1.0f produces a parabolic line y = x ^ 2. Add factor to 1.0f to increase the gradient effect (that is, it starts slowly and ends faster) */public AccelerateInterpolator (float factor) {mFactor = factor; mDoubleFactor = 2 * mFactor;} public AccelerateInterpolator (Context context, AttributeSet attrs) {TypedArray a = context. obtainStyledAttributes (attrs, com. android. internal. r. styleable. accelerateInterpolator); mFactor =. getFloat (com. android. internal. r. styleable. accelerateInterpolator_factor, 1.0f); mDoubleFactor = 2 * mFactor;. recycle () ;}@ Override public float getInterpolation (float input) {if (mFactor = 1.0f) {return input * input;} else {return (float) Math. pow (input, mDoubleFactor );}}}
The speed of acceleration is determined by the fractor parameter. When the fractor value is 1.0f, the animation accelerated track is equivalent to a parabolic line y = x ^ 2.
/*** An interpolation tool that starts fast and then slows down **/public class DecelerateInterpolator implements Interpolator {public DecelerateInterpolator () {}/***** @ param factor * the animation speed. When the factor value is set to 1.0f, a parabolic line from top to bottom y = x ^ 2 is generated. * Adding a factor to 1.0f will increase the effect of the gradient (that is, the start is faster and the end is slower) */public DecelerateInterpolator (float factor) {mFactor = factor ;} public DecelerateInterpolator (Context context, AttributeSet attrs) {TypedArray a = context. obtainStyledAttributes (attrs, com. android. internal. r. styleable. decelerateInterpolator); mFactor =. getFloat (com. android. internal. r. styleable. decelerateInterpolator_factor, 1.0f);. recycle () ;}@ Override public float getInterpolation (float input) {float result; if (mFactor = 1.0f) {result = (1.0f-(1.0f-input) * (1.0f-input);} else {result = (float) (1.0f-Math. pow (1.0f-input), 2 * mFactor);} return result;} private float mFactor = 1.0f ;}
If the fractor is 1.0f. The trajectory curve for its deceleration is 1-() ^ 2.
/*** A slow rate of change starts from the middle to the middle. */Public class implements Interpolator {public topology () {}@ SuppressWarnings ({"UnusedDeclaration"}) public AccelerateDecelerateInterpolator (Context context, AttributeSet attrs) {}@ Override public float getInterpolation (float input) {return (float) (Math. cos (input + 1) * Math. PI)/2.0f) + 0.5f ;}}
Public class LinearInterpolator implements Interpolator {public LinearInterpolator () {} public LinearInterpolator (Context context, AttributeSet attrs) {} public float getInterpolation (float input) {return input ;}}BounceInterpolator
/*** The interpolation of this interpolation device is in the bounce state. */Public class BounceInterpolator implements Interpolator {public BounceInterpolator () {}@ SuppressWarnings ({"UnusedDeclaration"}) public BounceInterpolator (Context context, AttributeSet attrs) {} private static float bounce (float t) {return t * 8.0f;} @ Override public float getInterpolation (float t) {// _ B (t) = t * 8 // bs (t) = _ B (t) for t <0.3535 // bs (t) = _ B (t-0.54719) + 0.7 for t <0.7408/bs (t) = _ B (t-0.8526) + 0.9 for t <0.9644/bs (t) = _ B (t-1.0435) + 0.95 for t <= 1.0 // B (t) = bs (t * 1.1226) t * = 1.1226f; if (t <0.3535f) return bounce (t ); else if (t <0.7408f) return bounce (t-0.54719f) + 0.7f; else if (t <0.9644f) return bounce (t-0.8526f) + 0.9f; else return bounce (t-1.0435f) + 0.95f ;}}
/*** An interpolation device that starts to swing backward and then moves forward. */Public class AnticipateInterpolator implements Interpolator {private final float mTension; public AnticipateInterpolator () {mTension = 2.0f;}/*** @ param tension * tightening degree, when the tightening program is 0.0f, there is no reverse force. The interpolation tool degrades to an accelerated interpolation tool y = x ^ 3. */Public AnticipateInterpolator (float tension) {mTension = tension;} public AnticipateInterpolator (Context context, AttributeSet attrs) {TypedArray a = context. obtainStyledAttributes (attrs, com. android. internal. r. styleable. anticipateInterpolator); mTension =. getFloat (com. android. internal. r. styleable. anticipateInterpolator_tension, 2.0f);. recycle () ;}@ Override public float getInterpolation (float t) {// a (t) = t * (tension + 1) * t-tension) return t * (mTension + 1) * t)-mTension );}}
/*** An interpolation tool starts to push up and then swing down to the lowest line. Then return to the lowest line. * <Hr/> * An interpolator where the change starts backward then flings forward and overshoots * the target value and finally goes back to the final value. */public class AnticipateOvershootInterpolator implements Interpolator {private final float mTension; public limit () {mTension = 2.0f * 1.5f;}/*** @ param tension * anticipation/overshoot ratio. When the value of tension is 0.0f, * does not have the anticipation/overshoot ratio. The interpolation tool degrades to an acceleration/deceleration interpolation tool. */Public AnticipateOvershootInterpolator (float tension) {mTension = tension * 1.5f;}/*** @ param tension Amount of anticipation/overshoot. when tension equals 0.0f, * there is no anticipation/overshoot and the interpolator becomes * a simple acceleration/deceleration interpolator. * @ param extraTension * times the value of tension. For example, in the above constructor, The extraTension value is 1.5f */public partition (float tension, float extraTension) {mTension = tension * extraTension;} public partition (Context context, AttributeSet attrs) {TypedArray a = context. obtainStyledAttributes (attrs, AnticipateOvershootInterpolator); mTension =. getFloat (AnticipateOvershootInterpolator_tension, 2.0f) *. getFloat (AnticipateOvershootInterpolator_extraTension, 1.5f);. recycle ();} private static float a (float t, float s) {return t * (s + 1) * t)-s );} private static float o (float t, float s) {return t * (s + 1) * t) + s );} @ Override public float getInterpolation (float t) {// a (t, s) = t * (s + 1) * t-s) // o (t, s) = t * (s + 1) * t + s) // f (t) = 0.5 * a (t * 2, tension * extraTension ), when t <0.5 // f (t) = 0.5 * (o (t * 2-2, tension * extraTension) + 2 ), when t <= 1.0 if (t <0.5f) return 0.5f * a (t * 2.0f, mTension); else return 0.5f * (o (t * 2.0f)-2.0f, mTension) + 2.0f );}}
/*** Repeats the animation with the specified period. The change rate curve is sine. */Public class CycleInterpolator implements Interpolator {/***** @ param cycles number of cycles to be repeated */public CycleInterpolator (float cycles) {mCycles = cycles ;} public CycleInterpolator (Context context, AttributeSet attrs) {TypedArray a = context. obtainStyledAttributes (attrs, com. android. internal. r. styleable. cycleInterpolator); mCycles =. getFloat (com. android. internal. r. styleable. cycleInterpolator_cycles, 1.0f);. recycle () ;}@ Override public float getInterpolation (float input) {return (float) (Math. sin (2 * mCycles * Math. PI * input);} private float mCycles ;}
/*** An interpolator where the change flings forward and overshoots the last value * then comes back. */public class OvershootInterpolator implements Interpolator {private final float mTension; public OvershootInterpolator () {mTension = 2.0f;}/*** @ param tension Amount of overshoot. when tension equals 0.0f, there is * no overshoot and the interpolator becomes a simple * deceleration interpolator. */public OvershootInterpolator (float tension) {mTension = tension;} public OvershootInterpolator (Context context, AttributeSet attrs) {TypedArray a = context. obtainStyledAttributes (attrs, com. android. internal. r. styleable. overshootInterpolator); mTension =. getFloat (com. android. internal. r. styleable. overshootInterpolator_tension, 2.0f);. recycle () ;}@ Override public float getInterpolation (float t) {// _ o (t) = t * (tension + 1) * t + tension) // o (t) = _ o (t-1) + 1 t-= 1.0f; return (t * (mTension + 1) * t) + mTension) + 1.0f; // plot {(x-1) (x-1) (tension + 1) (x-1) + tension) + 1, (0 <x <= 1 )}}}
When tension is set to 2 by default,
I am the dividing line of tiantiao
Reference: http://my.oschina.net/banxi/blog/135633