| java.lang.Object | ||||
| android.graphics.drawable.Drawable | ||||
| android.graphics.drawable.DrawableContainer | Drawable.Callback | |||
| android.graphics.drawable.AnimationDrawable | Runnable | |||
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 -->
<frames id="selected" oneshot="false">
<frame drawable="@drawable/wheel0" duration="50" />
<frame drawable="@drawable/wheel1" duration="50" />
<frame drawable="@drawable/wheel2" duration="50" />
<frame drawable="@drawable/wheel3" duration="50" />
<frame drawable="@drawable/wheel4" duration="50" />
<frame drawable="@drawable/wheel5" duration="50" />
</frames>
Here is the Java 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.setBackground(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()
| AnimationDrawable() |
| void | inflate(Resources r, XmlPullParser parser, AttributeSet attrs) | ||||
| 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. |
|||||
| 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
Methods inherited
from class
android.graphics.drawable.Drawable
Methods inherited
from class
java.lang.Object
Methods inherited
from interface
android.graphics.drawable.Drawable.Callback
Methods inherited
from interface
java.lang.Runnable
| XmlPullParserException | |
|---|---|
| IOException |
Indicates whether the animation is currently running or not.
| visible | 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. |
Starts the animation, looping if necessary. This method has no effect if the animation is running.
Stops the animation. This method has no effect if the animation is not running.
| what | The runnable that you no longer want called. |
|---|