interpolator

效果看這里,有動(dòng)畫(huà)展示
https://blog.csdn.net/cjh_android/article/details/51508634

AccelerateDecelerateInterpolator
@android:anim/accelerate_decelerate_interpolator
在動(dòng)畫(huà)開(kāi)始與結(jié)束的地方速率改變比較慢,在中間的時(shí)候加速

AccelerateInterpolator
@android:anim/accelerate_interpolator
在動(dòng)畫(huà)開(kāi)始的地方速率改變比較慢,然后開(kāi)始加速

AnticipateInterpolator
@android:anim/anticipate_interpolator
開(kāi)始的時(shí)候向后然后向前甩

AnticipateOvershootInterpolator
@android:anim/anticipate_overshoot_interpolator
開(kāi)始的時(shí)候向后然后向前甩一定值后返回最后的值

BounceInterpolator
@android:anim/bounce_interpolator
動(dòng)畫(huà)結(jié)束的時(shí)候彈起

CycleInterpolator
@android:anim/cycle_interpolator
動(dòng)畫(huà)循環(huán)播放特定的次數(shù),速率改變沿著正弦曲線

DecelerateInterpolator
@android:anim/decelerate_interpolator
在動(dòng)畫(huà)開(kāi)始的地方快然后慢

LinearInterpolator
@android:anim/linear_interpolator
以常量速率改變

OvershootInterpolator
@android:anim/overshoot_interpolator
向前甩一定值后再回到原來(lái)位置
各插值器的源碼

    /**
     * Maps a value representing the elapsed fraction of an animation to a value that represents
     * the interpolated fraction. This interpolated value is then multiplied by the change in
     * value of an animation to derive the animated value at the current elapsed animation time.
     *
     * @param input A value between 0 and 1.0 indicating our current point
     *        in the animation where 0 represents the start and 1.0 represents
     *        the end
     * @return The interpolation value. This value can be more than 1.0 for
     *         interpolators which overshoot their targets, or less than 0 for
     *         interpolators that undershoot their targets.
     */
    float getInterpolation(float input);

AccelerateDecelerateInterpolator

/**
 * An interpolator where the rate of change starts and ends slowly but
 * accelerates through the middle.
 */
    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 AccelerateInterpolator() {
        mFactor = 1.0f;
        mDoubleFactor = 2.0;
    }
    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 starts backward then flings forward.
 */
    public AnticipateInterpolator() {
        mTension = 2.0f;
    }
    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 goes back to the final value.
 */
   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;
    }
    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 bounces at the end.
 */
   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.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;
    }

CycleInterpolator

/**
 * Repeats the animation for a specified number of cycles. The
 * rate of change follows a sinusoidal pattern.
 */
  public CycleInterpolator(float cycles) {
        mCycles = cycles;
    }
    public float getInterpolation(float input) {
        return (float)(Math.sin(2 * mCycles * Math.PI * input));
    }

DecelerateInterpolator

/**
 * An interpolator where the rate of change starts out quickly and
 * and then decelerates.
 */
    public DecelerateInterpolator() {
    }

    /**
     * Constructor
     *
     * @param factor Degree to which the animation should be 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 evens slower)
     */
    public DecelerateInterpolator(float factor) {
        mFactor = factor;
    }
    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;

OvershootInterpolator

/**
 * An interpolator where the change flings forward and overshoots the last value
 * then comes back.
 */
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 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;
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 動(dòng)畫(huà)的基本原理是從開(kāi)始時(shí)間到結(jié)束時(shí)間一幀一幀的播放靜態(tài)圖像。Interpolator插值器來(lái)指定動(dòng)畫(huà)如何變化的東東...
    釘某人閱讀 2,257評(píng)論 0 6
  • 這是我這個(gè)系列的目錄,有興趣的可以看下: android 動(dòng)畫(huà)系列 - 目錄 首先要了解為什么需要插值器,因?yàn)樵谘a(bǔ)...
    前行的烏龜閱讀 6,186評(píng)論 0 4
  • 【Android 動(dòng)畫(huà)】 動(dòng)畫(huà)分類補(bǔ)間動(dòng)畫(huà)(Tween動(dòng)畫(huà))幀動(dòng)畫(huà)(Frame 動(dòng)畫(huà))屬性動(dòng)畫(huà)(Property ...
    Rtia閱讀 6,386評(píng)論 1 38
  • 1 背景 不能只分析源碼呀,分析的同時(shí)也要整理歸納基礎(chǔ)知識(shí),剛好有人微博私信讓全面說(shuō)說(shuō)Android的動(dòng)畫(huà),所以今...
    未聞椛洺閱讀 2,850評(píng)論 0 10
  • 花了大約四天的時(shí)間,看完整本《白夜行》。 這是第一次接觸推理小說(shuō),很久以前聽(tīng)別人說(shuō)起推理小說(shuō)的時(shí)候內(nèi)心總是持有一種...
    一粒花椒閱讀 728評(píng)論 0 0

友情鏈接更多精彩內(nèi)容