Member-only story

Android Animations Cookbook

Code on the Rocks
2 min readMay 28, 2020

--

In all honesty, this article is for my own reference but hopefully someone else can find it helpful too. I’ll be adding to it over time.

Basics

Single Property Animations

Use the ObjectAnimator to change the property. Most View properties are here. This section of the Property Animation guide also is good to have on hand.

ObjectAnimator.ofFloat(textView, "translationX", 100f).apply {
duration = 1000
start()
}

Multiple Property Animations

Create an AnimatorSet in the res/animator resource folder.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="500"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:propertyName="alpha"
android:valueFrom="1F"
android:valueTo="0F" />
<objectAnimator
android:duration="500"
android:propertyName="translationY"
android:valueTo="400F" />
</set>

Inflate the resource and set one target for the animation:

(AnimatorInflater.loadAnimator(main, R.animator.dig_down) as AnimatorSet).apply {
setTarget(myWebView)
start()
}

Recipes

Opacity

Property: “alpha”
Type: Float
Range
: 0F to 1F (opaque)

--

--

No responses yet