Basic animations
Last updated
Last updated
You can't learn how to run if you don't start walking first.
The Animation class has 5 known subclasses
AlphaAnimation (will fade in or out your view)
RotateAnimation (will rotate your view)
ScaleAnimation (will scale up or down your view)
TranslateAnimation (will move your view)
AnimationSet (for a combination of animations that should be played together on the same view)
When you want to animate one property of a view
When you want to animate more than one properties or
you want to animate a clickable view
android.animation
It makes it easy to animate any kind of property on any object by allowing you to define a start and end value and apply a time-based change on this attribute.
The Animator class is the superclass for classes which provide basic support for animations which can be started, ended, and have AnimatorListeners attached to them. These classes are:
Animator set
ValueAnimator
ObjectAnimator
TimeAnimator
ValueAnimator: provides a simple timing engine for running animations which calculate animated values. It runs in a custom handler to ensure that property changes happen on the UI thread.
ObjectAnimator: sets the animated values to the target objects.
TimeAnimator: provides a simple callback mechanism to listeners that is synchronized with all other animators in the system
AnimatorSet: This class plays a set of Animator objects in the specified order more or less as the AnimationSet class we saw earlier. That said, the animator set is more flexible and animations can be set up to play together, in sequence, or after a specified delay. In addition you can set it to play different animations on different objects and not just on the same one.
I found only one case of a simple animation that this did not work, when I wanted to animate only one layer of a LayerDrawable
*
All animations can be either from XML or programmatically.
Example ObjectAnimator
:
Property animation API provides also the ViewPropertyAnimator class that is a simple way to animate several properties in parallel, using a single Animator.
The good: it provides better performance for several simultaneous animations, because it will optimize invalidate calls to take place only once for several properties instead of each animated property independently causing its own invalidation. It also has a much simpler syntax!
The bad: it’s only for animating properties in parallel!
*If you want to find more information check this .