Android -- Interpolator

Source: Internet
Author: User

Android -- Interpolator
If the android-defined interpolators do not match your performance, you can also customize the interpolators Interpolator interface package android. animation;/*** the time interpolation tool 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 the class added before Android API11, which is called Interpolator. 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 TimeInter Polator directly.}/*** 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_fac Tor, 1.0f); mDoubleFactor = 2 * mFactor;. recycle () ;}@ Override public float getInterpolation (float input) {if (mFactor = 1.0f) {return input * input;} else {return (float) Math. the speed of pow (input, mDoubleFactor) ;}} 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. Image when fractor is not 1, the trajectory curve is y = x ^ (2 * fractor) (0 <x <= 1. (When fractor is 4) image if you want an animation that starts slowly and then suddenly accelerates quickly when using AccelerateInterpolator, set the fractor to a greater value. DecelerateInterpolator/*** a fast-start and slow-down interpolation tool **/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;}/*** 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 imple Ments Interpolator {public LinearInterpolator () {} public LinearInterpolator (Context context, AttributeSet attrs) {} public float getInterpolation (float input) {return input ;}} /*** 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 f Or 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 ;}}/*** A 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 that starts to push up and then moves 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 (Anticip AteOvershootInterpolator_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 cycle. 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 )}}}

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.