Layout Animation

As you have seen, frame-by-frame animation is a quick and dirty way to add visual effects to your Android applications. Layout animation is almost as simple. You'll use layout animation with the ListView and GridView, which are the two most commonly used controls in Android. Specifically, you'll use layout animation to add visual effects to the way each item in a ListView or GridView is displayed. In fact, you can use this type of animation on all controls derived from a ViewGroup.

As we pointed out at the beginning of this chapter, layout animation works by applying tweening principles to each view that is part of the layout being animated. Tweening is a process in which a number of the view's properties are changed at regular intervals. Every view in Android has a matrix that maps the view to the screen. By changing this matrix in a number of ways, you can accomplish scaling, rotation, and movement (translation) of the view. By changing the transparency of the view from 0 to 1, for example, you can accomplish what is called an alpha animation.

In this section, we will offer a simple test harness to learn, test, and experiment with layout-animation capabilities. We will show you how to attach a tweening animation to a ListView. We will also introduce and explain the idea of interpolators and their role in animation. The SDK documentation on interpolators is a bit vague, so we will clarify interpolator behavior by showing you relevant source code. We will also cover something called a LayoutAnimationController that mediates between an animation and a ViewGroup.

0 0

Post a comment