Planning the Layout Animation Test Harness

You can test all the layout-animation concepts we've covered using a simple ListView set in an activity. Once you have a ListView, you can attach an animation to it so that each list item will go through that animation.

Assume you have a scale animation that makes a view grow from 0 to its original size on the y axis. You can attach that animation to a ListView. When this happens, the ListView will animate each item in that list using this animation. You can set some additional parameters that extend the basic animation, such as animating the list from top to bottom or from bottom to top. You specify these parameters through an intermediate class that acts as a mediator between the individual animation and the list.

You can define both the individual animation and the mediator in XML files in the /res/ anim subdirectory. Once you have the mediator XML file, you can use that file as an input to the ListView in its own XML layout definition. This will become clear to you when you see the code listings we'll provide in the rest of this section. Once you have this basic setup working, you can start altering the individual animations to see how they impact the ListView display.

Our examples will cover scale animation, translate animation, rotate animation, alpha animation, and a combination of translate and alpha animation. If this high-level plan seems a bit vague, just hang tight; by the end of this section, you will know what we are talking about.

Before we embark on this exercise, you should see what the ListView will look like after the animation completes (see Figure 6-4).

Layout Animation Test

Layout Animation Test

Item 1

Item 2

Item 3

Item 4

Item 5

Item 6


Figure 6-4. The end result of animating the ListView

0 0

Post a comment