|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.graphics.drawable.Drawable
android.graphics.drawable.DrawableContainer
android.graphics.drawable.AnimationDrawable
public class AnimationDrawable
An object used to define frame-by-frame animations that can be used as a View object's background.
Each frame in a frame-by-frame animation is a drawable resource. The simplest way to create a frame-by-frame animation is to define the animation in an XML file in the drawable/ folder, set it as the background to a View object, then call AnimationDrawable.run() to start the animation, as shown here. More details about the format of the animation XML file are given in Frame by Frame Animation. spin_animation.xml file in res/drawable/ folder:
<!-- Animation frames are wheel0.png -- wheel5.png files inside the
res/drawable/ folder -->
<animation-list android:id="selected" android:oneshot="false">
<item android:drawable="@drawable/wheel0" android:duration="50" />
<item android:drawable="@drawable/wheel1" android:duration="50" />
<item android:drawable="@drawable/wheel2" android:duration="50" />
<item android:drawable="@drawable/wheel3" android:duration="50" />
<item android:drawable="@drawable/wheel4" android:duration="50" />
<item android:drawable="@drawable/wheel5" android:duration="50" />
</animation-list>
Here is the code to load and play this animation.
// Load the ImageView that will host the animation and // set its background to our AnimationDrawable XML resource. ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image); img.setBackgroundResource(R.drawable.spin_animation); // Get the background, which has been compiled to an AnimationDrawable object. AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); // Start the animation (looped playback by default). frameAnimation.start()
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class android.graphics.drawable.DrawableContainer |
|---|
DrawableContainer.DrawableContainerState |
| Nested classes/interfaces inherited from class android.graphics.drawable.Drawable |
|---|
Drawable.Callback, Drawable.ConstantState |
| Field Summary |
|---|
| Fields inherited from class android.graphics.drawable.Drawable |
|---|
mCallback |
| Constructor Summary | |
|---|---|
AnimationDrawable()
|
|
| Method Summary | |
|---|---|
void |
addFrame(Drawable frame,
int duration)
Add a frame to the animation |
int |
getDuration(int i)
|
Drawable |
getFrame(int index)
|
int |
getNumberOfFrames()
|
void |
inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs)
|
boolean |
isOneShot()
|
boolean |
isRunning()
Indicates whether the animation is currently running or not. |
void |
run()
This method exists for implementation purpose only and should not be called directly. |
void |
setOneShot(boolean oneShot)
Sets whether the animation should play once or repeat. |
boolean |
setVisible(boolean visible,
boolean restart)
Set whether this Drawable is visible. |
void |
start()
Starts the animation, looping if necessary. |
void |
stop()
Stops the animation. |
void |
unscheduleSelf(Runnable what)
Use the current Drawable.Callback implementation to have this Drawable
unscheduled. |
| Methods inherited from class android.graphics.drawable.DrawableContainer |
|---|
draw, getChangingConfigurations, getConstantState, getCurrent, getIntrinsicHeight, getIntrinsicWidth, getMinimumHeight, getMinimumWidth, getOpacity, getPadding, invalidateDrawable, isStateful, onBoundsChange, onLevelChange, onStateChange, scheduleDrawable, selectDrawable, setAlpha, setColorFilter, setConstantState, setDither, unscheduleDrawable |
| Methods inherited from class android.graphics.drawable.Drawable |
|---|
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromStream, createFromXml, createFromXmlInner, getBounds, getLevel, getState, getTransparentRegion, inflateWithAttributes, invalidateSelf, isVisible, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setFilterBitmap, setLevel, setState |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AnimationDrawable()
| Method Detail |
|---|
public boolean setVisible(boolean visible,
boolean restart)
Drawable
setVisible in class DrawableContainervisible - Set to true if visible, false if not.restart - You can supply true here to force the drawable to behave
as if it has just become visible, even if it had last
been set visible. Used for example to force animations
to restart.
public void start()
Starts the animation, looping if necessary. This method has no effect if the animation is running.
isRunning(),
stop()public void stop()
Stops the animation. This method has no effect if the animation is not running.
isRunning(),
start()public boolean isRunning()
Indicates whether the animation is currently running or not.
public void run()
This method exists for implementation purpose only and should not be
called directly. Invoke start() instead.
run in interface Runnablestart()public void unscheduleSelf(Runnable what)
DrawableDrawable.Callback implementation to have this Drawable
unscheduled. Does nothing if there is no Callback attached to the
Drawable.
unscheduleSelf in class Drawablewhat - The runnable that you no longer want called.Drawable.Callback.unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable)public int getNumberOfFrames()
public Drawable getFrame(int index)
public int getDuration(int i)
public boolean isOneShot()
public void setOneShot(boolean oneShot)
oneShot - Pass true if the animation should only play once
public void addFrame(Drawable frame,
int duration)
frame - The frame to addduration - How long in milliseconds the frame should appear
public void inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs)
throws XmlPullParserException,
IOException
inflate in class DrawableXmlPullParserException
IOException
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||