Deep Understanding of Physics-based Animations In Android

Image for post
Image for post

As of support library 26, Physics-based animations got available in Android, Spring Animation and Fling Animation. Both helps you implement Spring or Fling Animation of views without any complicated code.

How To Start

dependencies {
...
compile "com.android.support:support-dynamic-animation:26.1.0"
}

Spring Animation

Spring Animation has some attributes like stiffness or dumping ratio which determines how view springs.

You can make views moving, rotating, scaling with Spring Animation :)

Moving

Image for post
Image for post
Moving View

Rotating

Image for post
Image for post
Rotating View

Scaling

Image for post
Image for post
Scaling View

Fling Animation

Fling Animation comes in handy when you want to fling views, and it’s really easy to use.

Set the first velocity and friction. That it.

val flingAnimation = FlingAnimation(yourView, DynamicAnimation.X)
.setFriction(3f)
.setStartVelocity(10f)
flingAnimation.start()

Last

Recently, I created a library “CropMe” using Physics-based Animations.

It helps you crop image, is extremely smooth and easy. Please check this out and give me a STAR if you like it!

Written by

Android Engineer at AbemaTV Github: https://github.com/takusemba

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store