Android physics based animation

Physics based animation vs. Non-Physics based animation

If you want to create normal animation all you need is duration, start value, end value and interpolator. Animation is static and duration is fix. Velocity of animation is govern by duration of animation and interpolator. There is no external force involve here which is controlling progress of animation. Physics based animation is driven by force. Force you apply controls velocity of animation. Also you can modify target value of animation while animation is going on and physics based animation takes care of applying new force on existing velocity, which makes a continuous transition to the new target. To better understand difference between two look at the following figure.

Difference between object animator(Left) and physic based animation(Right)

Spring Animation

Animation of view property is driven by spring force. The properties of a spring, the value, and the velocity are used in creating a spring-based animation.

Fling Animation

Animation of view property is driven by frictional force. Fling animation has an initial momentum and gradually slows down.

Spring Animation

Spring animation is driven by spring force which depends on spring stiffness, damping ratio and object’s final position. It’s a same effect you get when you pull object tied to spring and release. Object bounce back and forth and finally comes to it’s initial position. Before diving into API it is important to understand properties of spring that determines spring force.

Spring Animation

Fling Animation

Fling animation is driven by frictional force. If friction is high object will come to rest quickly and if it is low object will travel more. It has an initial momentum, which is mostly received from the gesture velocity, and gradually slows down.

Fling Animation

Chained Spring Animation

Physics based animation API has two ways to start animation. First we already saw is using start() method. There is another way you can start animation and i.e using animateToFinalPosition() method. This method perform two tasks. First it will set the target value of animation and second it will start the animation, if it has not started. This will allow us to change the target value in middle of animation. In order to implement following chained spring animation this method will be helpful.

Chain Animation

Google Developer Expert for Android