Ugurcan Yildirim
Ugurcan Yildirim

Reputation: 6142

How to reduce Android BounceInterpolator bounce amplitude

Is there a way to reduce the amplitude of bounce effect while using BounceInterpolator for animations in Android? By default, it causes a bounce effect much more than I desire.

Upvotes: 9

Views: 2758

Answers (1)

Ishan Manchanda
Ishan Manchanda

Reputation: 479

Unfortunately, Android's BounceInterpolator doesn't provide that option. You'll need to write your own version to control the amplitude. Here is a simple version of the code that takes Amplitude and Frequency as Arguments in the Constructor. A simple web search will get you to the formula used below.

class MyBounceInterpolator implements android.view.animation.Interpolator {
    double mAmplitude = 1;
    double mFrequency = 10;

    MyBounceInterpolator() {
    }

    MyBounceInterpolator(double amp, double freq) {
        mAmplitude = amp;
        mFrequency = freq;
    }

    public float getInterpolation(float time) {
        return (float) (-1 * Math.pow(Math.E, -time/ mAmplitude) * Math.cos(mFrequency * time) + 1);
    }
}

Hope this helps

Upvotes: 11

Related Questions