Android Object Animator

Yağmur Erdoğan
ÇSTech
Published in
3 min readDec 22, 2022

--

🙋🏻‍♀ ️Hi everyone! What do you think about using animation to attract users’ attention? Today, we will learn to create animation using Object Animator!

Object Animator Structure

Structure

👉🏻 Duration specifies how long the animation will continue.

👉🏻 Start delay helps to add delay to animation start after invoking the start function.

👉🏻 Repeat count specifies how many times the animation will repeat. ObjectAnimator.INFINITE should be used if you want the animation to continue indefinitely.

👉🏻 The view is accelerated by “Interpolator”.

Animation Types

There are four different animation types. Alpha, scale, rotate and translate. Let’s examine them one by one.

Alpha Animation

The transparency of the image view can be changed with the alpha animation. Images can also be completely invisible.

Start and end values ​​range from 1 to 0. The state of the image itself corresponds to 1, and the state of being invisible to 0.

Alpha (1.0f, 0.0f)

Scale Animation

The size of the image can be changed with the scale animation. The size change is defined in x and y coordinates.

Scale X (1.0f, 0.5f)
Scale Y (1.0f, 0.5f)

Rotate Animation

Rotation animation is used to rotate the angle of the image.

The default position of the image is 0.

Rotation (0.0f, 45.0f)

Translate Animation

With the translation animation, the image can move in x and y coordinates.

Translation X (0.0f, 90.0f)
Translation Y (0.0f, 90.0f)
Translation Y ( (0.0f, 90.0f) with BounceInterpolator()
Coordinates

Road Animation

This animation includes all 4 animation types.

A view can be affected by different animations as below.

🌞 The sun is affected by rotation and alpha animations.

🚗 The car is affected by translation Y, scale X, and scale Y animations.

☁️ The clouds are only affected by translation X animation.

🌙 The sky, button, text, and moon are only affected by alpha animation.

All Animation Types Example

Multiple Animations

We can create a function as below to define multiple animations. Any animation added as a parameter will play together at the same time.

Sequential Animations

play sequentially should be used if animations are to be run sequentially rather than simultaneously. The second animation will start after the first animation finishes.

🦄 Sources

You can access the source code from my GitHub! 🎈

Udacity /Advanced Android with Kotlin/Lesson 6

--

--