Android Object Animator
🙋🏻♀ ️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
👉🏻 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.
Scale Animation
The size of the image can be changed with the scale animation. The size change is defined in x and y coordinates.
Rotate Animation
Rotation animation is used to rotate the angle of the image.
The default position of the image is 0.
Translate Animation
With the translation animation, the image can move in x and y 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.
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! 🎈