Sunday, February 24, 2013

Android beginner tutorial: Part 92 - Animation

Today we'll begin learning about Animations in Android.

In Android, just like in Flash, there are two animation types - Tween Animation and Frame Animation.

Any View in Android can be transformed in more than one ways - you can move, rotate, resize and change the alpha channel of them.

The animation transformations are all provided by android.view.animationpackages package. The main animation classes are AnimationSet, AlphaAnimation, RotateAnimation, ScaleAnimation and TranslateAnimation.

The AnimationSet class is used to group together other animations that are supposed to be played at the same time. If there are any properties set to an AnimationSet class, all the animations that belong to this set also inherit the properties.

The AlphaAnimation class is used for animations that change the alpha of the object. The RotateAnimation, ScaleAnimation and TranslateAnimation classes are used for rotating, scaling, and translating (moving) objects.

All animation transformations can be executed in a sequence or at once. Each transformation can have a set of parameters that are suitable only for its type of animation as well as global parameters that can be applied to all types of animations.

For example, all animations have start time as well as animation length time that you can set. If you want two animations to start at the same time, you set their start time to the same value.

Sequence of these animation commands can be created in Java or in an XML file, which might sound weird and inconvenient at first (especially if you are used to animations in Flash), but it's actually pretty easy to use. Moreover, it's really flexible, as by creating one animation XML file you can reuse it multiple times. Animating using an XML file is even more preferred than programmatically.

We'll take a closer look at these XML files used for animating in the next part.

Thanks for reading!

No comments:

Post a Comment