Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 326
Ugurcan Yildirim Avatar asked Oct 17 '16 13:10

Ugurcan Yildirim


1 Answers

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

like image 102
Ishan Manchanda Avatar answered Oct 12 '22 21:10

Ishan Manchanda