public class AnimationSet extends Animation
The way that AnimationSet inherits behavior from Animation is important to understand. Some of the Animation attributes applied to AnimationSet affect the AnimationSet itself, some are pushed down to the children, and some are ignored, as follows:
Build.VERSION_CODES.ICE_CREAM_SANDWICH
,
the behavior of these properties is the same in XML resources and at runtime (prior to that
release, the values set in XML were ignored for AnimationSet). That is, calling
setDuration(500)
on an AnimationSet has the same effect as declaring
android:duration="500"
in an XML resource for an AnimationSet object.Animation.AnimationListener, Animation.Description
ABSOLUTE, INFINITE, RELATIVE_TO_PARENT, RELATIVE_TO_SELF, RESTART, REVERSE, START_ON_FIRST_FRAME, ZORDER_BOTTOM, ZORDER_NORMAL, ZORDER_TOP
Constructor and Description |
---|
AnimationSet(boolean shareInterpolator)
Constructor to use when building an AnimationSet from code
|
AnimationSet(Context context,
AttributeSet attrs)
Constructor used when an AnimationSet is loaded from a resource.
|
Modifier and Type | Method and Description |
---|---|
void |
addAnimation(Animation a)
Add a child animation to this animation set.
|
protected AnimationSet |
clone()
Creates and returns a copy of this object.
|
long |
computeDurationHint()
The duration hint of an animation set is the maximum of the duration
hints of all of its component animations.
|
List<Animation> |
getAnimations() |
long |
getDuration()
The duration of an AnimationSet is defined to be the
duration of the longest child animation.
|
long |
getStartTime()
When this animation should start.
|
boolean |
getTransformation(long currentTime,
Transformation t)
The transformation of an animation set is the concatenation of all of its
component animations.
|
boolean |
hasAlpha()
Return true if this animation changes the view's alpha property.
|
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) |
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 |
setDuration(long durationMillis)
Sets the duration of every child animation.
|
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 |
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)
Sets the start time of this animation and all child animations
|
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.
|
applyTransformation, cancel, detach, ensureInterpolator, finalize, getBackgroundColor, getDetachWallpaper, getFillAfter, getFillBefore, getInterpolator, getInvalidateRegion, getRepeatCount, getRepeatMode, getScaleFactor, getStartOffset, getTransformation, getZAdjustment, hasEnded, hasStarted, isFillEnabled, isInitialized, resolveSize, setAnimationListener, setBackgroundColor, setDetachWallpaper, setFillEnabled, setInterpolator, setInterpolator, setListenerHandler, setRepeatCount, setZAdjustment, start, startNow
public AnimationSet(Context context, AttributeSet attrs)
context
- Application context to useattrs
- Attribute set from which to read valuespublic AnimationSet(boolean shareInterpolator)
shareInterpolator
- Pass true if all of the animations in this set
should use the interpolator associated with this AnimationSet.
Pass false if each animation should use its own interpolator.protected AnimationSet clone() throws CloneNotSupportedException
Object
x
, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone
. If a class and all of its superclasses (except
Object
) obey this convention, it will be the case that
x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone
before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays
are considered to implement the interface Cloneable
and that
the return type of the clone
method of an array type T[]
is T[]
where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object
does not itself implement the interface
Cloneable
, so calling the clone
method on an object
whose class is Object
will result in throwing an
exception at run time.
clone
in class Animation
CloneNotSupportedException
- if the object's class does not
support the Cloneable
interface. Subclasses
that override the clone
method can also
throw this exception to indicate that an instance cannot
be cloned.Cloneable
public void setFillAfter(boolean fillAfter)
Animation
AnimationSet
to chain
animations.setFillAfter
in class Animation
fillAfter
- true if the animation should apply its transformation after it endsAnimation.setFillEnabled(boolean)
public void setFillBefore(boolean fillBefore)
Animation
Animation.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.setFillBefore
in class Animation
fillBefore
- true if the animation should apply its transformation before it startsAnimation.setFillEnabled(boolean)
public void setRepeatMode(int repeatMode)
Animation
Animation.INFINITE
. Defaults to Animation.RESTART
.setRepeatMode
in class Animation
repeatMode
- Animation.RESTART
or Animation.REVERSE
public void setStartOffset(long startOffset)
Animation
AnimationSet
where some of the animations components start at different times.setStartOffset
in class Animation
startOffset
- When this Animation should start, in milliseconds from
the start time of the root AnimationSet.public boolean hasAlpha()
Animation
public void setDuration(long durationMillis)
Sets the duration of every child animation.
setDuration
in class Animation
durationMillis
- the duration of the animation, in milliseconds, for
every child in this setpublic void addAnimation(Animation a)
a
- Animation to add.public void setStartTime(long startTimeMillis)
setStartTime
in class Animation
startTimeMillis
- the start time in millisecondsAnimation.setStartTime(long)
public long getStartTime()
Animation
Animation.START_ON_FIRST_FRAME
.getStartTime
in class Animation
Animation.START_ON_FIRST_FRAME
public void restrictDuration(long durationMillis)
Animation
restrictDuration
in class Animation
durationMillis
- The maximum duration the animation is allowed
to run.public long getDuration()
getDuration
in class Animation
Animation.getDuration()
public long computeDurationHint()
computeDurationHint
in class Animation
Animation.computeDurationHint()
public void initializeInvalidateRegion(int left, int top, int right, int bottom)
initializeInvalidateRegion
in class Animation
public boolean getTransformation(long currentTime, Transformation t)
getTransformation
in class Animation
currentTime
- Where we are in the animation. This is wall clock time.t
- A transformation object that is provided by the
caller and will be filled in by the animation.Animation.getTransformation(long, android.view.animation.Transformation)
public void scaleCurrentDuration(float scale)
Animation
scaleCurrentDuration
in class Animation
scale
- The amount to scale the duration.Animation.scaleCurrentDuration(float)
public void initialize(int width, int height, int parentWidth, int parentHeight)
Animation
Objects that interpret Animations should call this method when
the sizes of the object being animated and its parent are known, and
before calling Animation.getTransformation(long, android.view.animation.Transformation)
.
initialize
in class Animation
width
- Width of the object being animatedheight
- Height of the object being animatedparentWidth
- Width of the animated object's parentparentHeight
- Height of the animated object's parentAnimation.initialize(int, int, int, int)
public void reset()
Animation
reset
in class Animation
Animation.initialize(int, int, int, int)
public List<Animation> getAnimations()
public boolean willChangeTransformationMatrix()
Animation
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.
willChangeTransformationMatrix
in class Animation
public boolean willChangeBounds()
Animation
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.
willChangeBounds
in class Animation