Animation API

Animation

android.view.animation
类 Animation

java.lang.Object
  android.view.animation.Animation
所有已实现的接口:
Cloneable
直接已知子类:
AlphaAnimation, AnimationSet, RotateAnimation, ScaleAnimation, TranslateAnimation

public abstract class Animation
extends Objectimplements Cloneable

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


嵌套类摘要
static interface
Animation.AnimationListener 
          An animation listener receives notifications from an animation.
 
字段摘要
static int
ABSOLUTE 
          The specified dimension is an absolute number of pixels.
static int INFINITE 
          Repeat the animation indefinitely.
static 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.
static int RELATIVE_TO_SELF 
          The specified dimension holds a float and should be multiplied by the height or width of the object being animated.
static int RESTART 
          When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation restarts from the beginning.
static int REVERSE 
          When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation plays backward (and then forward again).
static int START_ON_FIRST_FRAME 
          Can be used as the start time to indicate the start time should be the current time when getTransformation(long, Transformation) is invoked for the first animation frame.
static int ZORDER_BOTTOM 
          Requests that the content being animated be forced under all other content for the duration of the animation.
static int ZORDER_NORMAL 
          Requests that the content being animated be kept in its current Z order.
static int ZORDER_TOP 
          Requests that the content being animated be forced on top of all other content for the duration of the animation.
 
构造方法摘要
Animation() 
          Creates a new animation with a duration of 0ms, the default interpolator, with fillBefore set to true and fillAfter set to false
Animation(Context context, AttributeSet attrs) 
          Creates a new animation whose parameters come from the specified context and attributes set.
 
方法摘要
 long computeDurationHint() 
          Compute a hint at how long the entire animation may last, in milliseconds.
 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.
 void getInvalidateRegion(int left, int top, int right, int bottom, RectF invalidate, Transformation transformation) 
           
 int getRepeatCount() 
          Defines how many times the animation should repeat.
 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 should start.
 boolean getTransformation(long currentTime, Transformation outTransformation) 
          Gets the transformation to apply at a specified point in time.
 int getZAdjustment() 
          Returns the Z ordering mode to use while running the animation as previously set by setZAdjustment(int).
 boolean hasEnded() 
          Indicates whether this animation has ended or not.
 boolean hasStarted() 
          Indicates whether this animation has started or not.
 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.
 void initializeInvalidateRegion(int left, int top, int right, int bottom) 
           
 boolean isFillEnabled() 
          If fillEnabled is true, this animation will apply fillBefore and fillAfter.
 boolean isInitialized() 
          Whether or not the animation has been initialized.
 void reset() 
          Reset the initialization state of this animation.
 void restrictDuration(long durationMillis) 
          Ensure that the duration that this animation will run is not longer than durationMillis.
 void scaleCurrentDuration(float scale) 
          How much to scale the duration by.
 void setAnimationListener(Animation.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 setFillEnabled(boolean fillEnabled) 
          If fillEnabled is true, the animation will apply the value of fillBefore and fillAfter.
 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 setRepeatCount(int repeatCount) 
          Sets how many times the animation should be repeated.
 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 setZAdjustment(int zAdjustment) 
          Set the Z ordering mode to use while running the animation.
 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 willChangeBounds() 
          Indicates whether or not this animation will affect the bounds of the animated view.
 boolean willChangeTransformationMatrix() 
          Indicates whether or not this animation will affect the transformation matrix.
 
从类 java.lang.Object 继承的方法
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

INFINITE

public static final int INFINITE
Repeat the animation indefinitely.

另请参见:
常量字段值

RESTART

public static final int RESTART
When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation restarts from the beginning.

另请参见:
常量字段值

REVERSE

public static final int REVERSE
When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation plays backward (and then forward again).

另请参见:
常量字段值

START_ON_FIRST_FRAME

public static final int START_ON_FIRST_FRAME
Can be used as the start time to indicate the start time should be the current time when getTransformation(long, Transformation) is invoked for the first animation frame. This can is useful for short animations.

另请参见:
常量字段值

ABSOLUTE

public static final int ABSOLUTE
The specified dimension is an absolute number of pixels.

另请参见:
常量字段值

RELATIVE_TO_SELF

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.

另请参见:
常量字段值

RELATIVE_TO_PARENT

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.

另请参见:
常量字段值

ZORDER_NORMAL

public static final int ZORDER_NORMAL
Requests that the content being animated be kept in its current Z order.

另请参见:
常量字段值

ZORDER_TOP

public static final int ZORDER_TOP
Requests that the content being animated be forced on top of all other content for the duration of the animation.

另请参见:
常量字段值

ZORDER_BOTTOM

public static final int ZORDER_BOTTOM
Requests that the content being animated be forced under all other content for the duration of the animation.

另请参见:
常量字段值
构造方法详细信息

Animation

public Animation()
Creates a new animation with a duration of 0ms, the default interpolator, with fillBefore set to true and fillAfter set to false


Animation

public Animation(Context context,
                 AttributeSet attrs)
Creates a new animation whose parameters come from the specified context and attributes set.

参数:
context - the application environment
attrs - the set of attributes holding the animation parameters
方法详细信息

reset

public void reset()
Reset the initialization state of this animation.

另请参见:
initialize(int, int, int, int)

isInitialized

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

返回:
Has this animation been initialized.
另请参见:
initialize(int, int, int, int)

initialize

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, android.view.animation.Transformation).

参数:
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

setInterpolator

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.

参数:
context - The application environment
resID - The resource identifier of the interpolator to load

setInterpolator

public void setInterpolator(Interpolator i)
Sets the acceleration curve for this animation. Defaults to a linear interpolation.

参数:
i - The interpolator which defines the acceleration curve

setStartOffset

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.

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

setDuration

public void setDuration(long durationMillis)
How long this animation should last. The duration cannot be negative.

参数:
durationMillis - Duration in milliseconds

restrictDuration

public void restrictDuration(long durationMillis)
Ensure that the duration that this animation will run is not longer than  durationMillis. In addition to adjusting the duration itself, this ensures that the repeat count also will not make it run longer than the given time.

参数:
durationMillis - The maximum duration the animation is allowed to run.

scaleCurrentDuration

public void scaleCurrentDuration(float scale)
How much to scale the duration by.

参数:
scale - The amount to scale the duration.

setStartTime

public void setStartTime(long startTimeMillis)
When this animation should start. When the start time is set to START_ON_FIRST_FRAME, the animation will start the first time getTransformation(long, Transformation) is invoked. The time passed to this method should be obtained by calling AnimationUtils.currentAnimationTimeMillis() instead of System.currentTimeMillis().

参数:
startTimeMillis - the start time in milliseconds

start

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


startNow

public void startNow()
Convenience method to start the animation at the current time in milliseconds.


setRepeatMode

public void setRepeatMode(int repeatMode)
Defines what this animation should do when it reaches the end. This setting is applied only when the repeat count is either greater than 0 or INFINITE. Defaults to RESTART.

参数:
repeatMode - RESTART or REVERSE

setRepeatCount

public void setRepeatCount(int repeatCount)
Sets how many times the animation should be repeated. If the repeat count is 0, the animation is never repeated. If the repeat count is greater than 0 or INFINITE, the repeat mode will be taken into account. The repeat count is 0 by default.

参数:
repeatCount - the number of times the animation should be repeated

isFillEnabled

public boolean isFillEnabled()
If fillEnabled is true, this animation will apply fillBefore and fillAfter.

返回:
true if the animation will take fillBefore and fillAfter into account

setFillEnabled

public void setFillEnabled(boolean fillEnabled)
If fillEnabled is true, the animation will apply the value of fillBefore and fillAfter. Otherwise, fillBefore and fillAfter are ignored and the animation transformation is always applied.

参数:
fillEnabled - true if the animation should take fillBefore and fillAfter into account
另请参见:
setFillBefore(boolean), setFillAfter(boolean)

setFillBefore

public void setFillBefore(boolean fillBefore)
If fillBefore is true, this animation will apply its transformation before the start time of the animation. 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.

参数:
fillBefore - true if the animation should apply its transformation before it starts
另请参见:
setFillEnabled(boolean)

setFillAfter

public void setFillAfter(boolean fillAfter)
If fillAfter is true, the transformation that this animation performed will persist when it is finished. 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.

参数:
fillAfter - true if the animation should apply its transformation after it ends
另请参见:
setFillEnabled(boolean)

setZAdjustment

public void setZAdjustment(int zAdjustment)
Set the Z ordering mode to use while running the animation.

参数:
zAdjustment - The desired mode, one of ZORDER_NORMAL, ZORDER_TOP, or ZORDER_BOTTOM.

getInterpolator

public Interpolator getInterpolator()
Gets the acceleration curve type for this animation.

返回:
the Interpolator associated to this animation

getStartTime

public long getStartTime()
When this animation should start. If the animation has not startet yet, this method might return START_ON_FIRST_FRAME.

返回:
the time in milliseconds when the animation should start or START_ON_FIRST_FRAME

getDuration

public long getDuration()
How long this animation should last

返回:
the duration in milliseconds of the animation

getStartOffset

public long getStartOffset()
When this animation should start, relative to StartTime

返回:
the start offset in milliseconds

getRepeatMode

public int getRepeatMode()
Defines what this animation should do when it reaches the end.

返回:
either one of REVERSE or RESTART

getRepeatCount

public int getRepeatCount()
Defines how many times the animation should repeat. The default value is 0.

返回:
the number of times the animation should repeat, or INFINITE

getFillBefore

public boolean getFillBefore()
If fillBefore is true, this animation will apply its transformation before the start time of the animation.

返回:
true if the animation applies its transformation before it starts

getFillAfter

public boolean getFillAfter()
If fillAfter is true, this animation will apply its transformation after the end time of the animation.

返回:
true if the animation applies its transformation after it ends

getZAdjustment

public int getZAdjustment()
Returns the Z ordering mode to use while running the animation as previously set by setZAdjustment(int).

返回:
Returns one of ZORDER_NORMAL, ZORDER_TOP, or ZORDER_BOTTOM.

willChangeTransformationMatrix

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.

返回:
true if this animation will change the transformation matrix

willChangeBounds

public boolean willChangeBounds()

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

返回:
true if this animation will change the view's bounds

setAnimationListener

public void setAnimationListener(Animation.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.

参数:
listener - the animation listener to be notified

computeDurationHint

public long computeDurationHint()
Compute a hint at how long the entire animation may last, in milliseconds. Animations can be written to cause themselves to run for a different duration than what is computed here, but generally this should be accurate.


getTransformation

public boolean getTransformation(long currentTime,
                                 Transformation outTransformation)
Gets the transformation to apply at a specified point in time. Implementations of this method should always replace the specified Transformation or document they are doing otherwise.

参数:
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.
返回:
True if the animation is still running

hasStarted

public boolean hasStarted()

Indicates whether this animation has started or not.

返回:
true if the animation has started, false otherwise

hasEnded

public boolean hasEnded()

Indicates whether this animation has ended or not.

返回:
true if the animation has ended, false otherwise

getInvalidateRegion

public void getInvalidateRegion(int left,
                                int top,
                                int right,
                                int bottom,
                                RectF invalidate,
                                Transformation transformation)
参数:
left -
top -
right -
bottom -
invalidate -
transformation -

initializeInvalidateRegion

public void initializeInvalidateRegion(int left,
                                       int top,
                                       int right,
                                       int bottom)
参数:
left -
top -
right -
bottom -

你可能感兴趣的:(Animation API)