1) Implement the bounce interpolator

Next, we write the code that adds the bounce effect to the scale animation.

  • Create a new Java Class file in your app module and name it MyBounceInterpolator.
  • Open the Java file that was created and replace the class code with the following.
class MyBounceInterpolator implements android.view.animation.Interpolator { double mAmplitude = 1; double mFrequency = 10;

MyBounceInterpolator(double amplitude, double frequency) { mAmplitude = amplitude; mFrequency = frequency; }

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

I will explain how this code works in a moment.

2) Use the bounce interpolator

Finally, open your activity Java file again and replace the entire didTapButton method with the following code.