java.lang.Object | |
↳ | android.view.animation.Animation |
Known Direct Subclasses |
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. |
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:detachWallpaper | setDetachWallpaper(boolean) | Special option for window animations: if this window is on top of a wallpaper, don't animate the wallpaper with it. | |||||||||
android:duration | setDuration(long) | Amount of time (in milliseconds) for the animation to run. | |||||||||
android:fillAfter | setFillAfter(boolean) | When set to true, the animation transformation is applied after the animation is over. | |||||||||
android:fillBefore | setFillBefore(boolean) | When set to true or when fillEnabled is not set to true, the animation transformation is applied before the animation has started. | |||||||||
android:fillEnabled | setFillEnabled(boolean) | When set to true, the value of fillBefore is taken into account. | |||||||||
android:interpolator | setInterpolator(Interpolator) | Defines the interpolator used to smooth the animation movement in time. | |||||||||
android:repeatCount | setRepeatCount(int) | Defines how many times the animation should repeat. | |||||||||
android:repeatMode | setRepeatMode(int) | Defines the animation behavior when it reaches the end and the repeat count is greater than 0 or infinite. | |||||||||
android:startOffset | setStartOffset(long) | Delay in milliseconds before the animation runs, once start time is reached. | |||||||||
android:zAdjustment | setZAdjustment(int) | Allows for an adjustment of the Z ordering of the content being animated for the duration of the animation. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ABSOLUTE | The specified dimension is an absolute number of pixels. | |||||||||
int | INFINITE | Repeat the animation indefinitely. | |||||||||
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. | |||||||||
int | RELATIVE_TO_SELF | The specified dimension holds a float and should be multiplied by the height or width of the object being animated. | |||||||||
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. | |||||||||
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). | |||||||||
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. |
|||||||||
int | ZORDER_BOTTOM | Requests that the content being animated be forced under all other content for the duration of the animation. | |||||||||
int | ZORDER_NORMAL | Requests that the content being animated be kept in its current Z order. | |||||||||
int | ZORDER_TOP | Requests that the content being animated be forced on top of all other content for the duration of the animation. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new animation with a duration of 0ms, the default interpolator, with
fillBefore set to true and fillAfter set to false
| |||||||||||
Creates a new animation whose parameters come from the specified context and
attributes set.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Cancel the animation.
| |||||||||||
Compute a hint at how long the entire animation may last, in milliseconds.
| |||||||||||
Returns the background color behind the animation.
| |||||||||||
Return value of
setDetachWallpaper(boolean) . | |||||||||||
How long this animation should last
| |||||||||||
If fillAfter is true, this animation will apply its transformation
after the end time of the animation.
| |||||||||||
If fillBefore is true, this animation will apply its transformation
before the start time of the animation.
| |||||||||||
Gets the acceleration curve type for this animation.
| |||||||||||
Defines how many times the animation should repeat.
| |||||||||||
Defines what this animation should do when it reaches the end.
| |||||||||||
When this animation should start, relative to StartTime
| |||||||||||
When this animation should start.
| |||||||||||
Gets the transformation to apply at a specified point in time.
| |||||||||||
Gets the transformation to apply at a specified point in time.
| |||||||||||
Returns the Z ordering mode to use while running the animation as
previously set by
setZAdjustment(int) . | |||||||||||
Indicates whether this animation has ended or not. | |||||||||||
Indicates whether this animation has started or not. | |||||||||||
Initialize this animation with the dimensions of the object being
animated as well as the objects parents.
| |||||||||||
If fillEnabled is true, this animation will apply the value of fillBefore.
| |||||||||||
Whether or not the animation has been initialized.
| |||||||||||
Reset the initialization state of this animation.
| |||||||||||
Ensure that the duration that this animation will run is not longer
than durationMillis.
| |||||||||||
How much to scale the duration by.
| |||||||||||
Binds an animation listener to this animation. | |||||||||||
Set background behind animation.
| |||||||||||
If detachWallpaper is true, and this is a window animation of a window
that has a wallpaper background, then the window will be detached from
the wallpaper while it runs.
| |||||||||||
How long this animation should last.
| |||||||||||
If fillAfter is true, the transformation that this animation performed
will persist when it is finished.
| |||||||||||
If fillBefore is true, this animation will apply its transformation
before the start time of the animation.
| |||||||||||
If fillEnabled is true, the animation will apply the value of fillBefore.
| |||||||||||
Sets the acceleration curve for this animation.
| |||||||||||
Sets the acceleration curve for this animation.
| |||||||||||
Sets how many times the animation should be repeated.
| |||||||||||
Defines what this animation should do when it reaches the end.
| |||||||||||
When this animation should start relative to the start time.
| |||||||||||
When this animation should start.
| |||||||||||
Set the Z ordering mode to use while running the animation.
| |||||||||||
Convenience method to start the animation the first time
getTransformation(long, Transformation) is invoked. | |||||||||||
Convenience method to start the animation at the current time in
milliseconds.
| |||||||||||
Indicates whether or not this animation will affect the bounds of the animated view. | |||||||||||
Indicates whether or not this animation will affect the transformation matrix. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Helper for getTransformation.
| |||||||||||
Creates and returns a copy of this
Object . | |||||||||||
Gurantees that this animation has an interpolator.
| |||||||||||
Invoked when the garbage collector has detected that this instance is no longer reachable.
| |||||||||||
The scale factor is set by the call to
getTransformation . | |||||||||||
Convert the information in the description of a size to an actual
dimension
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Special option for window animations: if this window is on top of a wallpaper, don't animate the wallpaper with it.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol detachWallpaper
.
Amount of time (in milliseconds) for the animation to run.
Must be an integer value, such as "100
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol duration
.
When set to true, the animation transformation is applied after the animation is over. The default value is false. If fillEnabled is not set to true and the animation is not set on a View, fillAfter is assumed to be true.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol fillAfter
.
When set to true or when fillEnabled is not set to true, the animation transformation is applied before the animation has started. The default value is true.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol fillBefore
.
When set to true, the value of fillBefore is taken into account.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol fillEnabled
.
Defines the interpolator used to smooth the animation movement in time.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute
resource symbol interpolator
.
Defines how many times the animation should repeat. The default value is 0.
May be an integer value, such as "100
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
May be one of the following constant values.
Constant | Value | Description |
---|---|---|
infinite | -1 |
This corresponds to the global attribute
resource symbol repeatCount
.
Defines the animation behavior when it reaches the end and the repeat count is greater than 0 or infinite. The default value is restart.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
restart | 1 | The animation starts again from the beginning. |
reverse | 2 | The animation plays backward. |
This corresponds to the global attribute
resource symbol repeatMode
.
Delay in milliseconds before the animation runs, once start time is reached.
Must be an integer value, such as "100
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute
resource symbol startOffset
.
Allows for an adjustment of the Z ordering of the content being animated for the duration of the animation. The default value is normal.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
normal | 0 | The content being animated be kept in its current Z order. |
top | 1 | The content being animated is forced on top of all other content for the duration of the animation. |
bottom | -1 | The content being animated is forced under all other content for the duration of the animation. |
This corresponds to the global attribute
resource symbol zAdjustment
.
The specified dimension is an absolute number of pixels.
Repeat the animation indefinitely.
The specified dimension holds a float and should be multiplied by the height or width of the parent of the object being animated.
The specified dimension holds a float and should be multiplied by the height or width of the object being animated.
When the animation reaches the end and the repeat count is INFINTE_REPEAT or a positive value, the animation restarts from the beginning.
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).
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.
Requests that the content being animated be forced under all other content for the duration of the animation.
Requests that the content being animated be kept in its current Z order.
Requests that the content being animated be forced on top of all other content for the duration of the animation.
Creates a new animation with a duration of 0ms, the default interpolator, with fillBefore set to true and fillAfter set to false
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 |
Cancel the animation. Cancelling an animation invokes the animation
listener, if set, to notify the end of the animation.
If you cancel an animation manually, you must call reset()
before starting the animation again.
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.
Returns the background color behind the animation.
Return value of setDetachWallpaper(boolean)
.
How long this animation should last
If fillAfter is true, this animation will apply its transformation after the end time of the animation.
If fillBefore is true, this animation will apply its transformation
before the start time of the animation. If fillBefore is false and
fillEnabled
is true, the transformation will not be applied until
the start time of the animation.
Gets the acceleration curve type for this animation.
Interpolator
associated to this animationDefines how many times the animation should repeat. The default value is 0.
INFINITE
Defines what this animation should do when it reaches the end.
When this animation should start, relative to StartTime
When this animation should start. If the animation has not startet yet,
this method might return START_ON_FIRST_FRAME
.
START_ON_FIRST_FRAME
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 transformation object that is provided by the caller and will be filled in by the animation. |
scale | Scaling factor to apply to any inputs to the transform operation, such pivot points being rotated or scaled around. |
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 transformation object that is provided by the caller and will be filled in by the animation. |
Returns the Z ordering mode to use while running the animation as
previously set by setZAdjustment(int)
.
ZORDER_NORMAL
,
ZORDER_TOP
, or ZORDER_BOTTOM
.Indicates whether this animation has ended or not.
Indicates whether this animation has started or not.
Initialize this animation with the dimensions of the object being animated as well as the objects parents. (This is to support animation sizes being specified relative to these dimensions.)
Objects that interpret Animations should call this method when
the sizes of the object being animated and its parent are known, and
before calling getTransformation(long, 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 |
If fillEnabled is true, this animation will apply the value of fillBefore.
Whether or not the animation has been initialized.
Reset the initialization state of this animation.
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. |
---|
How much to scale the duration by.
scale | The amount to scale the duration. |
---|
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 |
---|
Set background behind animation.
bg | The background color. If 0, no background. Currently must be black, with any desired alpha level. |
---|
If detachWallpaper is true, and this is a window animation of a window that has a wallpaper background, then the window will be detached from the wallpaper while it runs. That is, the animation will only be applied to the window, and the wallpaper behind it will remain static.
detachWallpaper | true if the wallpaper should be detached from the animation |
---|
How long this animation should last. The duration cannot be negative.
durationMillis | Duration in milliseconds |
---|
IllegalArgumentException | if the duration is < 0 |
---|
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 to individual animations and when using an AnimationSet
to chain
animations.
fillAfter | true if the animation should apply its transformation after it ends |
---|
If fillBefore is true, this animation will apply its transformation
before the start time of the animation. Defaults to true if
setFillEnabled(boolean)
is not set to true.
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 |
---|
If fillEnabled is true, the animation will apply the value of fillBefore. Otherwise, fillBefore is ignored and the animation transformation is always applied until the animation ends.
fillEnabled | true if the animation should take the value of fillBefore into account |
---|
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 |
Sets the acceleration curve for this animation. Defaults to a linear interpolation.
i | The interpolator which defines the acceleration curve |
---|
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 |
---|
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. |
---|
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
currentAnimationTimeMillis()
instead of
currentTimeMillis()
.
startTimeMillis | the start time in milliseconds |
---|
Set the Z ordering mode to use while running the animation.
zAdjustment | The desired mode, one of ZORDER_NORMAL ,
ZORDER_TOP , or ZORDER_BOTTOM . |
---|
Convenience method to start the animation the first time
getTransformation(long, Transformation)
is invoked.
Convenience method to start the animation at the current time in milliseconds.
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.
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.
Helper for getTransformation. Subclasses should implement this to apply their transforms given an interpolation value. Implementations of this method should always replace the specified Transformation or document they are doing otherwise.
interpolatedTime | The value of the normalized time (0.0 to 1.0) after it has been run through the interpolation function. |
---|---|
t | The Transformation object to fill in with the current transforms. |
Creates and returns a copy of this Object
. The default
implementation returns a so-called "shallow" copy: It creates a new
instance of the same class and then copies the field values (including
object references) from this instance to the new instance. A "deep" copy,
in contrast, would also recursively clone nested objects. A subclass that
needs to implement this kind of cloning should call super.clone()
to create the new instance and then create deep copies of the nested,
mutable objects.
CloneNotSupportedException |
---|
Gurantees that this animation has an interpolator. Will use a AccelerateDecelerateInterpolator is nothing else was specified.
Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.
Note that objects that override finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
Throwable |
---|
The scale factor is set by the call to getTransformation
. Overrides of
getTransformation(long, Transformation, float)
will get this value
directly. Overrides of applyTransformation(float, Transformation)
can
call this method to get the value.
ScaleAnimation
and RotateAnimation
.
Convert the information in the description of a size to an actual dimension
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 |