Android animation interpolator: AcceletateDecelerate

Android animation interpolator: AcceletateDecelerate

AccelerateDecelerate:

y = cos((t+1)π)/2+0.5

 

可讓動畫看起來較平順,系統預設的interpolator也是AcceletateDecelerate

accelerateDecelerate

 

Demo:

 

 

Source:

public class AccelerateDecelerateInterpolator extends BaseInterpolator implements NativeInterpolatorFactory {
    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;
        // y = cos((t + 1)Math.PI)/2 + 0.5
    }

    @Override
    public long createNativeInterpolator() {
        return NativeInterpolatorFactoryHelper.createAccelerateDecelerateInterpolator();
    }
}