Android Interpolator
The first is how the Android system provides the transformation:
These methods will be reproduced in an article:
Ext.: http://www.cnblogs.com/mengdd/p/3346003.html
Interpolator in Interpolatorandroid in Android
Interpolator is used for time interpolation in animations, which is the function of mapping 0 to 1 of floating-point values to another floating-point value change.
This article lists several implementations of the interpolator provided by the Android API, lists the source code, and draws its mathematical curve with a program. (The project link is attached to the text).
Acceleratedecelerateinterpolator
/** * An interpolator where the rate of change starts and ends slowly but * accelerates through the middle. * */public class Acceleratedecelerateinterpolator implements Interpolator { public Acceleratedecelerateinterpolator () { } @SuppressWarnings ({"Unuseddeclaration"}) Public Acceleratedecelerateinterpolator (context context, AttributeSet attrs) { } public float getinterpolation ( Float input) { return (float) (Math.Cos ((input + 1) * Math.PI)/2.0f) + 0.5f;} }
Accelerateinterpolator
/** * An interpolator where the rate of change starts out slowly and and then accelerates. * */public class Accelerateinterpolator implements Interpolator {private final float mfactor; Private final double mdoublefactor; Public Accelerateinterpolator () {mfactor = 1.0f; Mdoublefactor = 2.0; }/** * Constructor * * @param factor degree to which the animation should is eased. Seting * Factor to 1.0f produces a y=x^2 parabola. Increasing factor above * 1.0f exaggerates the ease-in effect (i.e., it starts even * slower and EN DS evens faster) */public Accelerateinterpolator (float factor) {mfactor = factor; Mdoublefactor = 2 * mfactor; } public Accelerateinterpolator (context context, AttributeSet attrs) {TypedArray a = Context.obt Ainstyledattributes (Attrs, com.android.internal.r.styleable.accelerateinterpolator); Mfactor = A.getfloat (Com.androId.internal.r.styleable.accelerateinterpolator_factor, 1.0f); Mdoublefactor = 2 * mfactor; A.recycle (); public float getinterpolation (float input) {if (Mfactor = = 1.0f) {return input * input; } else {return (float) Math.pow (input, mdoublefactor); } }}
Anticipateinterpolator
/** * An interpolator where the change is starts backward then flings forward. */public class Anticipateinterpolator implements Interpolator {private final float mtension; Public Anticipateinterpolator () {mtension = 2.0f; }/** * @param tension Amount of anticipation. When tension equals 0.0f, there are * no anticipation and the interpolator becomes a simple * Acceleration Interpolator. */Public Anticipateinterpolator (float tension) {mtension = tension; } public Anticipateinterpolator (context context, AttributeSet attrs) {TypedArray a = Context.obtainstyledattrib Utes (Attrs, com.android.internal.r.styleable.anticipateinterpolator); Mtension = A.getfloat (com.android.internal.r.styleable.anticipateinterpolator_tension, 2.0f); A.recycle (); } public float getinterpolation (float t) {//A (t) = t * t * ((tension + 1) * t-tension) return T * T * ((mtension + 1) * t-mtension); }}
Anticipateovershootinterpolator
/** * An interpolator where the change starts backward then flings forward and overshoots * The target value and finally g OES back to the final value. */public class Anticipateovershootinterpolator implements Interpolator {private final float mtension; Public Anticipateovershootinterpolator () {mtension = 2.0f * 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. */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 Amount by which to multiply the tension. For instance, * to get the same overshoot as a overshootinterpolator with * A tension of 2.0f, you would use an extratension of 1.5f. */Public Anticipateovershootinterpolator (float tension, float extratension) {mtension = tension * extratension ; } public Anticipateovershootinterpolator (context context, AttributeSet attrs) {TypedArray a = Context.obtainsty Ledattributes (Attrs, anticipateovershootinterpolator); Mtension = A.getfloat (anticipateovershootinterpolator_tension, 2.0f) * A.getfloat (Anticipateovershootinterp Olator_extratension, 1.5f); A.recycle (); } private static float A (float T, float s) {return T * t * ((s + 1) * t-s); } private static float O (float t, float s) {return T * t * ((s + 1) * t + s); } public float getinterpolation (float t) {//A (t, s) = t * t * ((s + 1) * t-s)//O (t, s) = t * 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); }}
Bounceinterpolator
/** * An interpolator where the change is bounces at the end. */public class Bounceinterpolator implements Interpolator {public bounceinterpolator () { } @ Suppresswarnings ({"Unuseddeclaration"}) public Bounceinterpolator (context context, AttributeSet attrs) { } private static float bounce (float t) { return T * t * 8.0f; } public float getinterpolation (float t) { //_b (t) = 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.04 + 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; }}
Cycleinterpolator
/** * Repeats The animation for a specified number of cycles. The * Rate of change follows a sinusoidal pattern. * */public class Cycleinterpolator implements Interpolator {public cycleinterpolator (float cycles) { Mcycles = C ycles; } Public Cycleinterpolator (context context, AttributeSet attrs) { TypedArray a = context.obtainstyledattributes (Attrs, com.android.internal.r.styleable.cycleinterpolator); Mcycles = A.getfloat (Com.android.internal.r.styleable.cycleinterpolator_cycles, 1.0f); A.recycle (); } public float getinterpolation (float input) { return (float) (Math.sin (2 * mcycles * Math.PI * input)); private float Mcycles;}
A curve with a 2 o'clock parameter:
Decelerateinterpolator
/** * An interpolator where the rate of change starts out quickly and and then decelerates. * */public class Decelerateinterpolator implements Interpolator {public decelerateinterpolator () {}/** * C Onstructor * * @param factor degree to which the animation should is eased. Setting factor to 1.0f produces * an upside-down y=x^2 parabola. Increasing factor above 1.0f makes exaggerates the * ease-out effect (i.e., it starts even faster and ends even s slower) */public Decelerateinterpolator (float factor) {mfactor = factor; } public Decelerateinterpolator (context context, AttributeSet attrs) {TypedArray a = Context.obt Ainstyledattributes (Attrs, com.android.internal.r.styleable.decelerateinterpolator); Mfactor = A.getfloat (Com.android.internal.r.styleable.decelerateinterpolator_factor, 1.0f); A.recycle (); } public float getinterpolation (float input) {float result; if (Mfactor = = 1.0f) {result = (float) (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;}
Linearinterpolator
/** * An interpolator where the rate of change is constant * */public class Linearinterpolator implements Interpolator {
public Linearinterpolator () { } public Linearinterpolator (context context, AttributeSet attrs) { } Public float getinterpolation (float input) { return input; }}
Overshootinterpolator
/** * 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 are * 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.obtainstyledattribu TES (Attrs, Com.android.internal.r.styleable.overshootinterpolator); Mtension = A.getfloat (com.android.internal.r.styleable.overshootinterpolator_tension, 2.0f); A.recycle (); } public float getinterpolation (float t) {//_o (t) = t * t * ((tension + 1) * t + tension) O (t) = _o (t-1) + 1 T-= 1.0f; return T * t * ((mtension + 1) * t + mtension) + 1.0f; }}
2. For example, all transformations are actually the function curves between 0~1. So all the functions are in principle just a y = f (x) function.
Here is the custom interpolator:
//Baseinterpolater is basd on Added in API level//we just suing Interpolater Public Static classMyInterpolater2ImplementsInterpolator {Private Static FinalString TAG = "MyInterpolater2"; Private floatA = -1.0f; Private floatx2 = 2.0f; /*we defined an arc y = A (x-x1) (x-x2) * **/@Override Public floatGetinterpolation (floatinput) { if(Input <= 0.5) returnInput *input; Else return(1-input) * (1-input); } }
Animation of Android (2)