An easing function describes the value of a property given a percentage of completeness. Thanks to Robert Penner for defining equations which drove animations with ease.
How do we do this android ? First lets see how we do animations with ValueAnimator.
Setting up Activity
app/package.name/MainActivity.java
Our XML layout
Setup simple Animation
ValueAnimator class provides a simple timing engine for running animations which calculate animated values and set them on target objects .
AnimatorSet class plays a set of Animator objects in the specified order. Animations can be set up to play together, in sequence, or after a specified delay.
We will be using these two classes to make our first animation.
This animations seems so boring. We need somthing cool.
Easing to make it awesome
ValueAnimator class accepts an evaluator, which defines on how the value is derived. So we make use of setEvaluator function and put our easing equations there to get the desired animation.
So make a class Easing implementing TypeEvaluator
app/package.name/Easing.java
Now we have the evaluate methods which tell the ValueAnimator on how it should evaluate.
app/package.name/Easing.java
What’s the calculate method here?
This method decides which easing equation we are going to use. There is a lot mentioned about equations here. You can edit this method based on any of the equations given and get your desired animation.
app/package.name/Easing.java
Update MainAcvitity
Now we are good with the Easing class and ready to include it in our ValueAnimator.
app/package.name/MainActvity.java
Uh! is that enough ?
Find the source code of the entire sample over here, Easing on Android.