Basic Tweening Animation Types

Before we design the test harness to apply the various tweening animations, we'll give you some detail on the basic types of tweening animation:

• Scale animation: You use this type of animation to make a view smaller or larger either on the x axis or on the y axis. You can also specify the pivot point around which you want the animation to take place.

• Rotate animation: You use this to rotate a view around a pivot point by a certain number of degrees.

• Translate animation: You use this to move a view along the x axis or the y axis.

• Alpha animation: You use this to change the transparency of a view.

All of the parameter values associated with these animations have a from and a to flavor because you must specify the starting values and ending values for when the animation starts and ends. Each animation also allows duration as an argument and a time interpolator as an argument. We'll cover interpolators at the end of this section on layout animation, but for now, know that interpolators determine the rate of change of the animated argument during animation.

You'll define these animations as XML files in the /res/anim subdirectory. You will see this amply illustrated in the test harness, but Listing 6-5 shows a quick sample to cement your understanding of how these animations are described.

Listing 6-5. A Scale Animation Defined in an XML File at /res/anim/scale.xml

<set xmlns:android="" android:interpolator="@android:anim/accelerate_interpolator"> <scale android:fromXScale="1"







android:startOffset="100" />

Once you have this file, you can associate this animation with a layout; this means that each view in the layout will go through this animation. The test harness goes through this process in much more detail, as you'll see shortly.

This is a good place to point out that each of these animations is represented as a Java class in the android.view.animation package. The Java documentation for each of these classes describes not only their Java methods, but also the allowed XML arguments for each type of animation.

Now that you have enough background on animation types to understand layout animation, let's proceed to the design of the layout-animation test harness.

0 0

Post a comment