Android Guides | Samples

Android.Graphics.Drawables.AnimationDrawable Class

An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.

See Also: AnimationDrawable

Syntax

[Android.Runtime.Register("android/graphics/drawable/AnimationDrawable", DoNotGenerateAcw=true)]
public class AnimationDrawable : DrawableContainer, IAnimatable, IRunnable, IDisposable

Remarks

An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.

The simplest way to create a frame-by-frame animation is to define the animation in an XML file, placed in the res/drawable/ folder, and set it as the background to a View object. Then, call AnimationDrawable.Start to run the animation.

An AnimationDrawable defined in XML consists of a single <animation-list> element and a series of nested <item> tags. Each item defines a frame of the animation. See the example below.

spin_animation.xml file in res/drawable/ folder:

Here is the code to load and play this animation.

java Example

 // 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();

Developer Guides

For more information about animating with AnimationDrawable, read the Drawable Animation developer guide.

[Android Documentation]

Requirements

Namespace: Android.Graphics.Drawables
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Graphics.Drawables.AnimationDrawable are listed below.

See Also: DrawableContainer

Public Constructors

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

[read-only]
IsRunningBoolean. Indicates whether the animation is currently running or not.
[read-only]
NumberOfFramesInt32.
OneShotBoolean.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

AddFrame(Drawable, Int32)
Adds a frame to the animation
GetDuration(Int32) : Int32
GetFrame(Int32) : Drawable
Run()
This method exists for implementation purpose only and should not be called directly.
Start()
Starts the animation, looping if necessary.
Stop()
Stops the animation.