Unveiling 2D Animation


Build your own Android App Dev Empire

Get Instant Access

The previous chapters should've given you a solid introduction to UI programming in Android. In this chapter, we would like to further strengthen your ability to create intuitive and appealing applications on the Android Platform by covering the animation capabilities of the Android SDK. If our experience is any guide, we assert that animation brings a lot of fun to the staid, unanimated world of programming.

Animation is a process by which an object on a screen changes its color, position, size, or orientation over time. Android supports three types of animation: frame-by-frame animation, which occurs when a series of frames is drawn one after the other at regular intervals; layout animation, in which you animate views inside a container view such as lists and tables; and view animation, in which you animate any general-purpose view. The latter two types fall into the category of tweening animation, which involves the drawings in between the key drawings. You accomplish this kind of animation by changing the intermediate values at regular intervals and redrawing the surface. We will cover each type of animation using working examples and in-depth analysis.

Frame-by-frame animation is the simplest of the three animation types, so we'll cover that one in this chapter's first section. We'll show you how it works, how to tell a story using it, and how to use the AnimationDrawable class to execute the frames at a certain refresh rate. We will present an example, with screenshots and code, in which you'll animate an image of a ball moving along the circumference of a circle.

In the second section we'll cover layout animation, which is more involved than frame-by-frame animation but still easier than view animation. We will talk about scale animation (changing size), translate animation (changing position), rotate animation (changing orientation), and alpha animation (changing a color gradient). We will show you how to declare these animations in an XML file and associate the animation IDs with a container view such as a list box. As an example, you'll apply a variety of animation transformations to a series of text items in a list box. We will also cover interpolators, which define an animation's rate of change, and animation sets, which contain an aggregated set of individual animations.

In the last section on view animation, we will cover animating a view by changing the transformation matrices. You'll need a good understanding of transformation matrices to grasp the material in this section, so we'll provide several examples to illustrate their behavior. Android also introduces the idea of a Camera to simulate 3D-like viewing capabilities by projecting a 2D view moving in 3D space. This section will illustrate both of these ideas by taking a ListView and rotating it in 3D space.

Was this article helpful?

0 0

Post a comment