English | Site Directory

Android - An Open Handset Alliance Project

android.view.animation
public abstract class

android.view.animation.Animation

java.lang.Object
android.view.animation.Animation

Abstraction for an Animation that can be applied to Views, Surfaces, or other objects. See the animation package description file.

Nested Classes
Animation.AnimationListener

An animation listener receives notifications from an animation. 

Animation.Description Utility class to parse a string description of a size  
Known Direct Subclasses

Summary

Constants

      Value  
int  ABSOLUTE  The specified dimension is an absolute number of pixels.  0x00000000 
int  NO_REPEAT  Don't do anything when the animation ends.  0x00000000 
int  RELATIVE_TO_PARENT  The specified dimension holds a float and should be multiplied by the height or width of the parent of the object being animated.  0x00000002 
int  RELATIVE_TO_SELF  The specified dimension holds a float and should be multiplied by the height or width of the object being animated.  0x00000001 
int  REPEAT  Replay the animation from the beginning.  0x00000001 
int  REVERSE  Replay the animation backwards (then forwards again).  0x00000002 

Fields

protected      boolean  mCycleFlip   
protected      long  mDurationMillis   
protected      boolean  mEnded   
protected      boolean  mFillAfter   
protected      boolean  mFillBefore   
protected      boolean  mInitialized   
protected      Interpolator  mInterpolator   
protected      AnimationListener  mListener   
protected      int  mRepeatMode   
protected      long  mStartOffsetMillis   
protected      long  mStartTimeMillis   
protected      boolean  mStarted   

Public Constructors

          Animation()
          Animation(Context context, AttributeSet attrs)

Public Methods

        long  getDuration()
How long this animation should last
        boolean  getFillAfter()
If fillAfter is true, this animation will apply its transformation after the end time of the animation.
        boolean  getFillBefore()
If fillBefore is true, this animation will apply its transformation before the start time of the animation.
        Interpolator  getInterpolator()
Gets the acceleration curve type for this animation.
        int  getRepeatMode()
Defines what this animation should do when it reaches the end.
        long  getStartOffset()
When this animation should start, relative to StartTime
        long  getStartTime()
When this animation was started
        boolean  getTransformation(long currentTime, Transformation outTransformation)
Gets the transformation to apply at a specified point in time
        void  initialize(int width, int height, int parentWidth, int parentHeight)
Initialize this animation with the dimensions of the object being animated as well as the objects parents.
        boolean  isEnded()

Indicates whether this animation has ended or not.

        boolean  isInitialized()
Whether or not the animation has been initialized.
        boolean  isStarted()

Indicates whether this animation has started or not.

        void  reset()
Reset the initialization state of this animation.
        void  scaleCurrentDuration(float scale)
How much to scale the duration by.
        void  setAnimationListener(AnimationListener listener)

Binds an animation listener to this animation.

        void  setDuration(long durationMillis)
How long this animation should last.
        void  setFillAfter(boolean fillAfter)
If fillAfter is true, the transformation that this animation performed will persist when it is finished.
        void  setFillBefore(boolean fillBefore)
If fillBefore is true, this animation will apply its transformation before the start time of the animation.
        void  setInterpolator(Context context, int resID)
Sets the acceleration curve for this animation.
        void  setInterpolator(Interpolator i)
Sets the acceleration curve for this animation.
        void  setRepeatMode(int repeatMode)
Defines what this animation should do when it reaches the end.
        void  setStartOffset(long startOffset)
When this animation should start relative to the start time.
        void  setStartTime(long startTimeMillis)
When this animation should start.
        void  start()
Convenience method to start the animation the first time getTransformation(long, Transformation) is invoked.
        void  startNow()
Convenience method to start the animation at the current time in milliseconds.
        boolean  willChangeTargetViewBounds()

Indicates whether or not this animation will affect the current bounds of the target view.

        boolean  willChangeTransformationMatrix()

Indicates whether or not this animation will affect the transformation matrix.

Protected Methods

        void  applyTransformation(float interpolatedTime, Transformation t)
Helper for getTransformation.
        void  ensureInterpolator()
Gurantees that this animation has an interpolator.
        float  resolveSize(int type, float value, int size, int parentSize)
Convert the information in the description of a size to an actual dimension
Methods inherited from class java.lang.Object

Details

Constants

public static final int ABSOLUTE

The specified dimension is an absolute number of pixels.
Constant Value: 0 (0x00000000)

public static final int NO_REPEAT

Don't do anything when the animation ends.
Constant Value: 0 (0x00000000)

public static final int RELATIVE_TO_PARENT

The specified dimension holds a float and should be multiplied by the height or width of the parent of the object being animated.
Constant Value: 2 (0x00000002)

public static final int RELATIVE_TO_SELF

The specified dimension holds a float and should be multiplied by the height or width of the object being animated.
Constant Value: 1 (0x00000001)

public static final int REPEAT

Replay the animation from the beginning. Will repeat indefinitely.
Constant Value: 1 (0x00000001)

public static final int REVERSE

Replay the animation backwards (then forwards again). Will repeat indefinitely.
Constant Value: 2 (0x00000002)

Fields

protected boolean mCycleFlip

protected long mDurationMillis

protected boolean mEnded

protected boolean mFillAfter

protected boolean mFillBefore

protected boolean mInitialized

protected Interpolator mInterpolator

protected AnimationListener mListener

protected int mRepeatMode

protected long mStartOffsetMillis

protected long mStartTimeMillis

protected boolean mStarted

Public Constructors

public Animation()

public Animation(Context context, AttributeSet attrs)

Public Methods

public long getDuration()

How long this animation should last

Returns

  • the duration in milliseconds of the animation

public boolean getFillAfter()

If fillAfter is true, this animation will apply its transformation after the end time of the animation.

Returns

  • true if the animation applies its transformation after it ends

public boolean getFillBefore()

If fillBefore is true, this animation will apply its transformation before the start time of the animation.

Returns

  • true if the animation applies its transformation before it starts

public Interpolator getInterpolator()

Gets the acceleration curve type for this animation.

Returns

public int getRepeatMode()

Defines what this animation should do when it reaches the end.

Returns

public long getStartOffset()

When this animation should start, relative to StartTime

Returns

  • the start offset in milliseconds

public long getStartTime()

When this animation was started

Returns

  • the time in milliseconds when the animation was started

public boolean getTransformation(long currentTime, Transformation outTransformation)

Gets the transformation to apply at a specified point in time

Parameters

currentTime Where we are in the animation. This is wall clock time.
outTransformation A tranformation object that is provided by the caller and will be filled in by the animation.

Returns

  • True if the animation is still running

public void initialize(int width, int height, int parentWidth, int parentHeight)

Initialize this animation with the dimensions of the object being animated as well as the objects parents. (This is to support animation sizes being specifed relative to these dimensions.)

Objects that interpret a Animations should call this method when the sizes of the object being animated and its parent are known, and before calling getTransformation(long, Transformation).

Parameters

width Width of the object being animated
height Height of the object being animated
parentWidth Width of the animated object's parent
parentHeight Height of the animated object's parent

public boolean isEnded()

Indicates whether this animation has ended or not.

Returns

  • true if the animation has ended, false otherwise

public boolean isInitialized()

Whether or not the animation has been initialized.

Returns

  • Has this animation been initialized.

public boolean isStarted()

Indicates whether this animation has started or not.

Returns

  • true if the animation has started, false otherwise

public void reset()

Reset the initialization state of this animation.

public void scaleCurrentDuration(float scale)

How much to scale the duration by.

Parameters

scale The amount to scale the duration.

public void setAnimationListener(AnimationListener listener)

Binds an animation listener to this animation. The animation listener is notified of animation events such as the end of the animation or the repetition of the animation.

Parameters

listener the animation listener to be notified

public void setDuration(long durationMillis)

How long this animation should last.

Parameters

durationMillis Duration in milliseconds

public void setFillAfter(boolean fillAfter)

If fillAfter is true, the transformation that this animation performed will persist when it is finished. Defaults to true if not set. Note that this applies when using an AnimationSet to chain animations. The transformation is not applied before the AnimationSet itself starts.

Parameters

fillAfter true if the animation should apply its transformation after it ends

public void setFillBefore(boolean fillBefore)

If fillBefore is true, this animation will apply its transformation before the start time of the animation. Defaults to false if not set. Note that this applies when using an AnimationSet to chain animations. The transformation is not applied before the AnimationSet itself starts.

Parameters

fillBefore true if the animation should apply its transformation before it starts

public void setInterpolator(Context context, int resID)

Sets the acceleration curve for this animation. The interpolator is loaded as a resource from the specified context.

Parameters

context The application environment
resID The resource identifier of the interpolator to load

public void setInterpolator(Interpolator i)

Sets the acceleration curve for this animation. Defaults to a linear interpolation.

Parameters

i The interpolator which defines the acceleration curve

public void setRepeatMode(int repeatMode)

Defines what this animation should do when it reaches the end. Defaults to NO_REPEAT

Parameters

repeatMode One of NO_REPEAT, REPEAT, or REVERSE

public void setStartOffset(long startOffset)

When this animation should start relative to the start time. This is most useful when composing complex animations using an AnimationSet where some of the animations components start at different times.

Parameters

startOffset When this Animation should start, in milliseconds from the start time of the root AnimationSet.

public void setStartTime(long startTimeMillis)

When this animation should start. When the start time is set to -1, the animation will start the first time getTransformation(long, Transformation) is invoked. The time passed to this method should be obtained by calling currentAnimationTimeMillis() instead of currentTimeMillis().

Parameters

startTimeMillis the start time in milliseconds

public void start()

Convenience method to start the animation the first time getTransformation(long, Transformation) is invoked.

public void startNow()

Convenience method to start the animation at the current time in milliseconds.

public boolean willChangeTargetViewBounds()

Indicates whether or not this animation will affect the current bounds of the target view. For instance, a fade animation will not affect the bounds whereas a scale animation will.

Returns

  • true if this animation will change the bounds of the target view

public boolean willChangeTransformationMatrix()

Indicates whether or not this animation will affect the transformation matrix. For instance, a fade animation will not affect the matrix whereas a scale animation will.

Returns

  • true if this animation will change the transformation matrix

Protected Methods

protected void applyTransformation(float interpolatedTime, Transformation t)

Helper for getTransformation. Subclasses should implement this to apply their transforms given an interpolation value.

Parameters

interpolatedTime The value of the normalized time (0.0 to 1.0) after it has been run through the interpolation function.
t The Transofrmation object to fill in with the current transforms.

protected void ensureInterpolator()

Gurantees that this animation has an interpolator. Will use a AccelerateDecelerateInterpolator is nothing else was specified.

protected float resolveSize(int type, float value, int size, int parentSize)

Convert the information in the description of a size to an actual dimension

Parameters

type One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
value The dimension associated with the type parameter
size The size of the object being animated
parentSize The size of the parent of the object being animated

Returns

  • The dimension to use for the animation
Build m5-rc15g - 14 May 2008 12:50