Animation

Tweened Animation

Android can perform simple animation on a graphic, or a series of graphics. These include rotations, fading, moving, and stretching.

Source file format: XML file, one resource per file, one root tag with no <?xml> declaration

Resource file location: res/anim/some_file.xml

Compiled resource datatype: Resource pointer to an Animation.

Resource reference name:

  • Java: R.anim.some_file
  • XML: @[package:]anim/some_file

Syntax

The file must have a single root element: this will be either a single <alpha>, <scale>, <translate>, <rotate>, interpolator element, or <set> element that holds groups of these elements (which may include another <set>). By default, all elements are applied simultaneously. To have them occur sequentially, you must specify the startOffset attribute.



Elements and Attributes

<set>
A container that can recursively hold itself or other animations. Represents an AnimationSet. You can include as many child elements of the same or different types as you like. Supports the following attribute:

  • shareInterpolator - Whether to share the same Interpolator among all immediate child elements.

<alpha>
A fading animation. Represents an AlphaAnimation. Supports the following attributes:

  • fromAlpha - 0.0 to 1.0, where 0.0 is transparent.
  • toAlpha - 0.0 to 1.0, where 0.0 is transparent.

<scale>
A resizing animation. Represents a ScaleAnimation. You can specify what is the center point of the image (the pinned center), from which it grows outward (or inward), by specifying pivotX and pivotY. So, for example, if these were 0, 0 (top left corner), all growth would be down and to the right. scale supports the following attributes:

  • fromXScale - Starting X size, where 1.0 is no change.
  • toXScale - Ending X size, where 1.0 is no change.
  • fromYScale - Starting Y size, where 1.0 is no change.
  • toYScale - Ending Y size, where 1.0 is no change.
  • pivotX - The X coordinate of the pinned center.
  • pivotY - The Y coordinate of the pinned center.
 
<translate>
A vertical/horizontal motion animation. Represents a TranslateAnimation. Supports the following attributes in any of the following three formats: values from -100 to 100, ending with "%", indicating a percentage relative to itself; values from -100 to 100, ending in "%p", indicating a percentage relative to its parent; a float with no suffix, indicating an absolute value.

  • fromXDelta - Starting X location.
  • toXDelta - Ending X location.
  • fromYDelta - Starting Y location.
  • toYDelta - Ending Y location.
 
<rotate>
A rotation animation. Represents a RotateAnimation. Supports the following attributes:

  • fromDegrees - Starting rotation, in degrees.
  • toDegrees - Ending rotation, in degrees.
  • pivotX - The X coordinate of the center of rotation, in pixels, where (0,0) is the top left corner.
  • pivotY - The Y coordinate of the center of rotation, in pixels, where (0,0) is the top left corner.
 
<interpolator tag>
You can also use any of the interpolator subclass elements defined in R.styleable. Examples include <CycleInterpolator>, <EaseInInterpolator>, and <EaseOutInterpolator>. These objects define a velocity curve that describes how quickly a visual action takes place on a timeline (fast at first and slow later, slow at first and gradually faster, and so on).

In addition to the attributes defined for each element above, the elements <alpha>, <scale>, <translate>, <rotate>, and <set> all support the following attributes (inherited from the Animation class):

duration
Duration, in milliseconds, for this effect.
startOffset
Offset start time for this effect, in milliseconds.
fillBefore
When set true, the animation transformation is applied before the animation begins.
fillAfter
When set true, the animation transformation is applied after the animation ends.
repeatCount
Defines the number of times the animation should repeat.
repeatMode
Defines the animation behavior when it reaches the end and the repeat count is greater than 0. Options are to either restart or reverse the animation.
zAdjustment
Defines the z-axis ordering mode to use when running the animation (normal, top, or bottom).
interpolator
You can optionally set an interpolator for each element to determine how quickly or slowly it performs its effect over time. For example, slow at the beginning and faster at the end for EaseInInterpolator, and the reverse for EaseOutInterpolator. A list of interpolators is given in R.anim. To specify these, use the syntax @android:anim/interpolatorName.

For more discussion and animation code samples, see the discussion in the 2D Graphics document.


(Ex) fade.xml



(Ex) hold.xml



(Ex) zoom_enter.xml



(Ex) zoom_exit.xml


'old > XML Attr' 카테고리의 다른 글

XML Attributes_TextView  (0) 2010.02.22
XML Attributes_LinearLayout  (0) 2010.02.22
Posted by jazzlife
,