In order to achieve some effect when we write the animation, we often need to set the Interpolator, which is used to simulate the real life scene.
Interpolator (interpolator) is used to modify the animation effect, define the rate of change of animation, can make the existing animation effect accelerated (acceleration), decelerated (deceleration), repeated (repetition), bounced (bounce) and so on.
Structure diagram:
Common interpolator:
Acceleratedecelerateinterpolator rate changes at the beginning and end of the animation are slower, accelerating in the middle
Accelerateinterpolator at the beginning of the animation the rate change is slow, and then start to accelerate
Anticipateinterpolator starts back and then moves forward.
Anticipateovershootinterpolator starts back and then dumps a certain value and returns the last value.
Bounceinterpolator animation at the end of the play
Cycleinterpolator Animation Loop plays a specific number of times, rate changes along the sine curve
Decelerateinterpolator in the beginning of the animation and then slowly
Linearinterpolator change at constant rate
Overshootinterpolator forward a certain value before returning to its original position.
If the above interpolator does not meet your requirements, you can customize the interpolator.
Let's look at an effect
Here I've customized a interpolator to achieve a constant rotation.
public class Myinterpolator extends Linearinterpolator {private float factor;public myinterpolator () {this.factor = 0.15f ;} @Overridepublic float getinterpolation (float input) {return (float) (Math.pow (2, -10 * input) * Math.sin ((Input-factor/ 4) * (2 * Math.PI)/factor) + 1);}}
Code Link: Click to open link
An explanation of the use of Android animation interpolator