Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [XML Attrs](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#lattrs) \| [Ctors](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#inhmethods)

# AnimationDrawable

*** ** * ** ***


`
public


class
AnimationDrawable
`


`


`

`


`

`

extends https://developer.android.com/reference/android/graphics/drawable/DrawableContainer


`

`


implements

https://developer.android.com/reference/android/graphics/drawable/Animatable,

https://developer.android.com/reference/java/lang/Runnable


`

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||||
| ↳ | [android.graphics.drawable.Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable) |||
|   | ↳ | [android.graphics.drawable.DrawableContainer](https://developer.android.com/reference/android/graphics/drawable/DrawableContainer) ||
|   |   | ↳ | android.graphics.drawable.AnimationDrawable |

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/android/graphics/drawable/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:

```
 <!-- Animation frames are wheel0.png through wheel5.png
     files inside the res/drawable/ folder -->
 <animation-list android:id="@+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();
 
```

### Developer Guides

For more information about animating with `AnimationDrawable`, read the
[Drawable Animation](https://developer.android.com/guide/topics/graphics/drawable-animation)
developer guide.

<br />

## Summary

| ### XML attributes ||
|---|---|
| [`android:drawable`](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#attr_android:drawable) | Reference to a drawable resource to use for the frame. |
| [`android:duration`](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#attr_android:duration) | Amount of time (in milliseconds) to display this frame. |
| [`android:oneshot`](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#attr_android:oneshot) | If true, the animation will only run a single time and then stop. |
| [`android:variablePadding`](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#attr_android:variablePadding) | If true, allows the drawable's padding to change based on the current state that is selected. |
| [`android:visible`](https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#attr_android:visible) | Provides initial visibility state of the drawable; the default value is false. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#AnimationDrawable()() ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#addFrame(android.graphics.drawable.Drawable,%20int)(https://developer.android.com/reference/android/graphics/drawable/Drawable frame, int duration) ` Adds a frame to the animation |
| ` int` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#getDuration(int)(int i) ` |
| ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#getFrame(int)(int index) ` |
| ` int` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#getNumberOfFrames()() ` |
| ` void` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#inflate(android.content.res.Resources,%20org.xmlpull.v1.XmlPullParser,%20android.util.AttributeSet,%20android.content.res.Resources.Theme)(https://developer.android.com/reference/android/content/res/Resources r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser parser, https://developer.android.com/reference/android/util/AttributeSet attrs, https://developer.android.com/reference/android/content/res/Resources.Theme theme) ` Inflate this Drawable from an XML resource optionally styled by a theme. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#isOneShot()() ` |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#isRunning()() ` Indicates whether the animation is currently running or not. |
| ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#mutate()() ` Make this drawable mutable. |
| ` void` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#run()() ` This method exists for implementation purpose only and should not be called directly. |
| ` void` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#setOneShot(boolean)(boolean oneShot) ` Sets whether the animation should play once or repeat. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#setVisible(boolean,%20boolean)(boolean visible, boolean restart) ` Sets whether this AnimationDrawable is visible. |
| ` void` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#start()() ` Starts the animation from the first frame, looping if necessary. |
| ` void` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#stop()() ` Stops the animation at the current frame. |
| ` void` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#unscheduleSelf(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable what) ` Use the current `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` implementation to have this Drawable unscheduled. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#setConstantState(android.graphics.drawable.DrawableContainer.DrawableContainerState)(https://developer.android.com/reference/android/graphics/drawable/DrawableContainer.DrawableContainerState state) ` |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer ` |---|---| | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#applyTheme(android.content.res.Resources.Theme)(https://developer.android.com/reference/android/content/res/Resources.Theme theme) ` Applies the specified theme to this Drawable and its children. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#canApplyTheme()() ` | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#draw(android.graphics.Canvas)(https://developer.android.com/reference/android/graphics/Canvas canvas) ` Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter). | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getAlpha()() ` Gets the current alpha value for the drawable. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getChangingConfigurations()() ` Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. | | ` https://developer.android.com/reference/android/graphics/drawable/Drawable.ConstantState` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getConstantState()() ` Return a `https://developer.android.com/reference/android/graphics/drawable/Drawable.ConstantState` instance that holds the shared state of this Drawable. | | ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getCurrent()() ` | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getHotspotBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect outRect) ` Populates `outRect` with the hotspot bounds. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getIntrinsicHeight()() ` Returns the drawable's intrinsic height. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getIntrinsicWidth()() ` Returns the drawable's intrinsic width. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getMinimumHeight()() ` Returns the minimum height suggested by this Drawable. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getMinimumWidth()() ` Returns the minimum width suggested by this Drawable. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getOpacity()() ` *This method is deprecated. This method is no longer used in graphics optimizations* | | ` https://developer.android.com/reference/android/graphics/Insets` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getOpticalInsets()() ` Return in insets the layout insets suggested by this Drawable for use with alignment operations during layout. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getOutline(android.graphics.Outline)(https://developer.android.com/reference/android/graphics/Outline outline) ` Called to get the drawable to populate the Outline that defines its drawing area. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#getPadding(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect padding) ` Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#hasFocusStateSpecified()() ` Indicates whether this drawable has at least one state spec explicitly specifying `https://developer.android.com/reference/android/R.attr#state_focused`. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#invalidateDrawable(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable who) ` Called when the drawable needs to be redrawn. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#isAutoMirrored()() ` Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#isStateful()() ` Indicates whether this drawable will change its appearance based on state. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#jumpToCurrentState()() ` If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations. | | ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#mutate()() ` Make this drawable mutable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#onBoundsChange(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect bounds) ` Override this in your subclass to change appearance if you vary based on the bounds. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#onLayoutDirectionChanged(int)(int layoutDirection) ` Called when the drawable's resolved layout direction changes. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#onLevelChange(int)(int level) ` Override this in your subclass to change appearance if you vary based on level. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#onStateChange(int[])(int[] state) ` Override this in your subclass to change appearance if you recognize the specified state. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#scheduleDrawable(android.graphics.drawable.Drawable,%20java.lang.Runnable,%20long)(https://developer.android.com/reference/android/graphics/drawable/Drawable who, https://developer.android.com/reference/java/lang/Runnable what, long when) ` A Drawable can call this to schedule the next frame of its animation. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#selectDrawable(int)(int index) ` Sets the currently displayed drawable by index. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setAlpha(int)(int alpha) ` Specify an alpha value for the drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setAutoMirrored(boolean)(boolean mirrored) ` Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setColorFilter(android.graphics.ColorFilter)(https://developer.android.com/reference/android/graphics/ColorFilter colorFilter) ` Specify an optional color filter for the drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setConstantState(android.graphics.drawable.DrawableContainer.DrawableContainerState)(https://developer.android.com/reference/android/graphics/drawable/DrawableContainer.DrawableContainerState state) ` | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setDither(boolean)(boolean dither) ` Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setEnterFadeDuration(int)(int ms) ` Change the global fade duration when a new drawable is entering the scene. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setExitFadeDuration(int)(int ms) ` Change the global fade duration when a new drawable is leaving the scene. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setHotspot(float,%20float)(float x, float y) ` Specifies the hotspot's location within the drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setHotspotBounds(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setTintBlendMode(android.graphics.BlendMode)(https://developer.android.com/reference/android/graphics/BlendMode blendMode) ` Specifies a tint blending mode for this drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setTintList(android.content.res.ColorStateList)(https://developer.android.com/reference/android/content/res/ColorStateList tint) ` Specifies tint color for this drawable as a color state list. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#setVisible(boolean,%20boolean)(boolean visible, boolean restart) ` Set whether this Drawable is visible. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/DrawableContainer#unscheduleDrawable(android.graphics.drawable.Drawable,%20java.lang.Runnable)(https://developer.android.com/reference/android/graphics/drawable/Drawable who, https://developer.android.com/reference/java/lang/Runnable what) ` A Drawable can call this to unschedule an action previously scheduled with `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback#scheduleDrawable(android.graphics.drawable.Drawable,%20java.lang.Runnable,%20long)`. | ||
| From class ` https://developer.android.com/reference/android/graphics/drawable/Drawable ` |---|---| | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#applyTheme(android.content.res.Resources.Theme)(https://developer.android.com/reference/android/content/res/Resources.Theme t) ` Applies the specified theme to this Drawable and its children. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#canApplyTheme()() ` | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#clearColorFilter()() ` Removes the color filter for this drawable. | | ` final https://developer.android.com/reference/android/graphics/Rect` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#copyBounds()() ` Return a copy of the drawable's bounds in a new Rect. | | ` final void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#copyBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect bounds) ` Return a copy of the drawable's bounds in the specified Rect (allocated by the caller). | | ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#createFromPath(java.lang.String)(https://developer.android.com/reference/java/lang/String pathName) ` Create a drawable from file path name. | | ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#createFromResourceStream(android.content.res.Resources,%20android.util.TypedValue,%20java.io.InputStream,%20java.lang.String,%20android.graphics.BitmapFactory.Options)(https://developer.android.com/reference/android/content/res/Resources res, https://developer.android.com/reference/android/util/TypedValue value, https://developer.android.com/reference/java/io/InputStream is, https://developer.android.com/reference/java/lang/String srcName, https://developer.android.com/reference/android/graphics/BitmapFactory.Options opts) ` *This method was deprecated in API level 28. Prefer the version without an Options object.* | | ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#createFromResourceStream(android.content.res.Resources,%20android.util.TypedValue,%20java.io.InputStream,%20java.lang.String)(https://developer.android.com/reference/android/content/res/Resources res, https://developer.android.com/reference/android/util/TypedValue value, https://developer.android.com/reference/java/io/InputStream is, https://developer.android.com/reference/java/lang/String srcName) ` Create a drawable from an inputstream, using the given resources and value to determine density information. | | ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#createFromStream(java.io.InputStream,%20java.lang.String)(https://developer.android.com/reference/java/io/InputStream is, https://developer.android.com/reference/java/lang/String srcName) ` Create a drawable from an inputstream | | ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#createFromXml(android.content.res.Resources,%20org.xmlpull.v1.XmlPullParser)(https://developer.android.com/reference/android/content/res/Resources r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser parser) ` Create a drawable from an XML document. | | ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#createFromXml(android.content.res.Resources,%20org.xmlpull.v1.XmlPullParser,%20android.content.res.Resources.Theme)(https://developer.android.com/reference/android/content/res/Resources r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser parser, https://developer.android.com/reference/android/content/res/Resources.Theme theme) ` Create a drawable from an XML document using an optional `https://developer.android.com/reference/android/content/res/Resources.Theme`. | | ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#createFromXmlInner(android.content.res.Resources,%20org.xmlpull.v1.XmlPullParser,%20android.util.AttributeSet,%20android.content.res.Resources.Theme)(https://developer.android.com/reference/android/content/res/Resources r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser parser, https://developer.android.com/reference/android/util/AttributeSet attrs, https://developer.android.com/reference/android/content/res/Resources.Theme theme) ` Create a drawable from inside an XML document using an optional `https://developer.android.com/reference/android/content/res/Resources.Theme`. | | ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#createFromXmlInner(android.content.res.Resources,%20org.xmlpull.v1.XmlPullParser,%20android.util.AttributeSet)(https://developer.android.com/reference/android/content/res/Resources r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser parser, https://developer.android.com/reference/android/util/AttributeSet attrs) ` Create from inside an XML document. | | ` abstract void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#draw(android.graphics.Canvas)(https://developer.android.com/reference/android/graphics/Canvas canvas) ` Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter). | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getAlpha()() ` Gets the current alpha value for the drawable. | | ` final https://developer.android.com/reference/android/graphics/Rect` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getBounds()() ` Return the drawable's bounds Rect. | | ` https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getCallback()() ` Return the current `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` implementation attached to this Drawable. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getChangingConfigurations()() ` Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. | | ` https://developer.android.com/reference/android/graphics/ColorFilter` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getColorFilter()() ` Returns the current color filter, or `null` if none set. | | ` https://developer.android.com/reference/android/graphics/drawable/Drawable.ConstantState` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getConstantState()() ` Return a `https://developer.android.com/reference/android/graphics/drawable/Drawable.ConstantState` instance that holds the shared state of this Drawable. | | ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getCurrent()() ` | | ` https://developer.android.com/reference/android/graphics/Rect` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getDirtyBounds()() ` Return the drawable's dirty bounds Rect. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getHotspotBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect outRect) ` Populates `outRect` with the hotspot bounds. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getIntrinsicHeight()() ` Returns the drawable's intrinsic height. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getIntrinsicWidth()() ` Returns the drawable's intrinsic width. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getLayoutDirection()() ` Returns the resolved layout direction for this Drawable. | | ` final int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getLevel()() ` Retrieve the current level. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getMinimumHeight()() ` Returns the minimum height suggested by this Drawable. | | ` int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getMinimumWidth()() ` Returns the minimum width suggested by this Drawable. | | ` abstract int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getOpacity()() ` *This method was deprecated in API level 29. This method is no longer used in graphics optimizations* | | ` https://developer.android.com/reference/android/graphics/Insets` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getOpticalInsets()() ` Return in insets the layout insets suggested by this Drawable for use with alignment operations during layout. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getOutline(android.graphics.Outline)(https://developer.android.com/reference/android/graphics/Outline outline) ` Called to get the drawable to populate the Outline that defines its drawing area. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getPadding(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect padding) ` Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. | | ` int[]` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getState()() ` Describes the current state, as a union of primitive states, such as `https://developer.android.com/reference/android/R.attr#state_focused`, `https://developer.android.com/reference/android/R.attr#state_selected`, etc. | | ` https://developer.android.com/reference/android/graphics/Region` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#getTransparentRegion()() ` Returns a Region representing the part of the Drawable that is completely transparent. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#hasFocusStateSpecified()() ` Indicates whether this drawable has at least one state spec explicitly specifying `https://developer.android.com/reference/android/R.attr#state_focused`. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#inflate(android.content.res.Resources,%20org.xmlpull.v1.XmlPullParser,%20android.util.AttributeSet,%20android.content.res.Resources.Theme)(https://developer.android.com/reference/android/content/res/Resources r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser parser, https://developer.android.com/reference/android/util/AttributeSet attrs, https://developer.android.com/reference/android/content/res/Resources.Theme theme) ` Inflate this Drawable from an XML resource optionally styled by a theme. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#inflate(android.content.res.Resources,%20org.xmlpull.v1.XmlPullParser,%20android.util.AttributeSet)(https://developer.android.com/reference/android/content/res/Resources r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser parser, https://developer.android.com/reference/android/util/AttributeSet attrs) ` Inflate this Drawable from an XML resource. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#invalidateSelf()() ` Use the current `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` implementation to have this Drawable redrawn. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#isAutoMirrored()() ` Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#isFilterBitmap()() ` | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#isProjected()() ` Whether this drawable requests projection. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#isStateful()() ` Indicates whether this drawable will change its appearance based on state. | | ` final boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#isVisible()() ` | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#jumpToCurrentState()() ` If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations. | | ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#mutate()() ` Make this drawable mutable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#onBoundsChange(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect bounds) ` Override this in your subclass to change appearance if you vary based on the bounds. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#onLayoutDirectionChanged(int)(int layoutDirection) ` Called when the drawable's resolved layout direction changes. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#onLevelChange(int)(int level) ` Override this in your subclass to change appearance if you vary based on level. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#onStateChange(int[])(int[] state) ` Override this in your subclass to change appearance if you recognize the specified state. | | ` static int` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#resolveOpacity(int,%20int)(int op1, int op2) ` Return the appropriate opacity value for two source opacities. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#scheduleSelf(java.lang.Runnable,%20long)(https://developer.android.com/reference/java/lang/Runnable what, long when) ` Use the current `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` implementation to have this Drawable scheduled. | | ` abstract void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setAlpha(int)(int alpha) ` Specify an alpha value for the drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setAutoMirrored(boolean)(boolean mirrored) ` Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setBounds(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Specify a bounding rectangle for the Drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect bounds) ` Specify a bounding rectangle for the Drawable. | | ` final void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setCallback(android.graphics.drawable.Drawable.Callback)(https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback cb) ` Bind a `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` object to this Drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setChangingConfigurations(int)(int configs) ` Set a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setColorFilter(int,%20android.graphics.PorterDuff.Mode)(int color, https://developer.android.com/reference/android/graphics/PorterDuff.Mode mode) ` *This method was deprecated in API level 29. use `https://developer.android.com/reference/android/graphics/drawable/Drawable#setColorFilter(android.graphics.ColorFilter)` with an instance of `https://developer.android.com/reference/android/graphics/BlendModeColorFilter`* | | ` abstract void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setColorFilter(android.graphics.ColorFilter)(https://developer.android.com/reference/android/graphics/ColorFilter colorFilter) ` Specify an optional color filter for the drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setDither(boolean)(boolean dither) ` Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setFilterBitmap(boolean)(boolean filter) ` Set to true to have the drawable filter its bitmaps with bilinear sampling when they are scaled or rotated. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setHotspot(float,%20float)(float x, float y) ` Specifies the hotspot's location within the drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setHotspotBounds(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds. | | ` final boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setLayoutDirection(int)(int layoutDirection) ` Set the layout direction for this drawable. | | ` final boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setLevel(int)(int level) ` Specify the level for the drawable. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setState(int[])(int[] stateSet) ` Specify a set of states for the drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setTint(int)(int tintColor) ` Specifies tint color for this drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setTintBlendMode(android.graphics.BlendMode)(https://developer.android.com/reference/android/graphics/BlendMode blendMode) ` Specifies a tint blending mode for this drawable. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setTintList(android.content.res.ColorStateList)(https://developer.android.com/reference/android/content/res/ColorStateList tint) ` Specifies tint color for this drawable as a color state list. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setTintMode(android.graphics.PorterDuff.Mode)(https://developer.android.com/reference/android/graphics/PorterDuff.Mode tintMode) ` Specifies a tint blending mode for this drawable. | | ` boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#setVisible(boolean,%20boolean)(boolean visible, boolean restart) ` Set whether this Drawable is visible. | | ` void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable#unscheduleSelf(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable what) ` Use the current `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` implementation to have this Drawable unscheduled. | ||
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback#invalidateDrawable(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable who) ` Called when the drawable needs to be redrawn. | | ` abstract void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback#scheduleDrawable(android.graphics.drawable.Drawable,%20java.lang.Runnable,%20long)(https://developer.android.com/reference/android/graphics/drawable/Drawable who, https://developer.android.com/reference/java/lang/Runnable what, long when) ` A Drawable can call this to schedule the next frame of its animation. | | ` abstract void` | ` https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback#unscheduleDrawable(android.graphics.drawable.Drawable,%20java.lang.Runnable)(https://developer.android.com/reference/android/graphics/drawable/Drawable who, https://developer.android.com/reference/java/lang/Runnable what) ` A Drawable can call this to unschedule an action previously scheduled with `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback#scheduleDrawable(android.graphics.drawable.Drawable,%20java.lang.Runnable,%20long)`. | ||
| From interface ` https://developer.android.com/reference/android/graphics/drawable/Animatable ` |---|---| | ` abstract boolean` | ` https://developer.android.com/reference/android/graphics/drawable/Animatable#isRunning()() ` Indicates whether the animation is running. | | ` abstract void` | ` https://developer.android.com/reference/android/graphics/drawable/Animatable#start()() ` Starts the drawable's animation. | | ` abstract void` | ` https://developer.android.com/reference/android/graphics/drawable/Animatable#stop()() ` Stops the drawable's animation. | ||
| From interface ` https://developer.android.com/reference/java/lang/Runnable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/lang/Runnable#run()() ` When an object implementing interface `Runnable` is used to create a thread, starting the thread causes the object's `run` method to be called in that separately executing thread. | ||

## XML attributes

### android:drawable

Reference to a drawable resource to use for the frame. If not
given, the drawable must be defined by the first child tag.

May be a reference to another resource, in the form
"`@[+][*package*:]*type*/*name*`" or a theme
attribute in the form
"`?[*package*:]*type*/*name*`".

<br />

### android:duration

Amount of time (in milliseconds) to display this frame.

May be an integer value, such as "`100`".

<br />

### android:oneshot

If true, the animation will only run a single time and then
stop. If false (the default), it will continually run,
restarting at the first frame after the last has finished.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:variablePadding

If true, allows the drawable's padding to change based on the
current state that is selected. If false, the padding will
stay the same (based on the maximum padding of all the states).
Enabling this feature requires that the owner of the drawable
deal with performing layout when the state changes, which is
often not supported.

May be a boolean value, such as "`true`" or
"`false`".

<br />

### android:visible

Provides initial visibility state of the drawable; the default
value is false. See
`https://developer.android.com/reference/android/graphics/drawable/Drawable#setVisible(boolean,%20boolean)`.

May be a boolean value, such as "`true`" or
"`false`".

<br />

## Public constructors

### AnimationDrawable

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AnimationDrawable ()
```

<br />

<br />

## Public methods

### addFrame

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void addFrame (Drawable frame, 
                int duration)
```

Adds a frame to the animation

<br />

| Parameters ||
|---|---|
| `frame` | `Drawable`: The frame to add. This value cannot be `null`. <br /> |
| `duration` | `int`: How long in milliseconds the frame should appear <br /> |

### getDuration

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getDuration (int i)
```

<br />

<br />

| Parameters ||
|---|---|
| `i` | `int` <br /> |

| Returns ||
|---|---|
| `int` | The duration in milliseconds of the frame at the specified index <br /> |

### getFrame

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Drawable getFrame (int index)
```

<br />

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable` | The Drawable at the specified frame index <br /> |

### getNumberOfFrames

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getNumberOfFrames ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | The number of frames in the animation <br /> |

### inflate

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void inflate (Resources r, 
                XmlPullParser parser, 
                AttributeSet attrs, 
                Resources.Theme theme)
```

Inflate this Drawable from an XML resource optionally styled by a theme.
This can't be called more than once for each Drawable. Note that framework may have called
this once to create the Drawable instance from XML resource.

<br />

| Parameters ||
|---|---|
| `r` | `Resources`: Resources used to resolve attribute values. This value cannot be `null`. <br /> |
| `parser` | `XmlPullParser`: XML parser from which to inflate this Drawable. This value cannot be `null`. <br /> |
| `attrs` | `AttributeSet`: Base set of attribute values. This value cannot be `null`. <br /> |
| `theme` | `Resources.Theme`: Theme to apply, may be null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |
| `https://developer.android.com/reference/org/xmlpull/v1/XmlPullParserException` |   |

### isOneShot

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isOneShot ()
```

<br />

<br />

| Returns ||
|---|---|
| `boolean` | True of the animation will play once, false otherwise <br /> |

### isRunning

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isRunning ()
```

Indicates whether the animation is currently running or not.

<br />

| Returns ||
|---|---|
| `boolean` | true if the animation is running, false otherwise <br /> |

### mutate

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Drawable mutate ()
```

Make this drawable mutable. This operation cannot be reversed. A mutable
drawable is guaranteed to not share its state with any other drawable.
This is especially useful when you need to modify properties of drawables
loaded from resources. By default, all drawables instances loaded from
the same resource share a common state; if you modify the state of one
instance, all the other instances will receive the same modification.

Calling this method on a mutable Drawable will have no effect.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable` | This value cannot be `null`. <br /> |

### run

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void run ()
```

This method exists for implementation purpose only and should not be
called directly. Invoke `https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#start()` instead.

<br />

**See also:**

- `https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#start()`

### setOneShot

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setOneShot (boolean oneShot)
```

Sets whether the animation should play once or repeat.

<br />

| Parameters ||
|---|---|
| `oneShot` | `boolean`: Pass true if the animation should only play once <br /> |

### setVisible

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean setVisible (boolean visible, 
                boolean restart)
```

Sets whether this AnimationDrawable is visible.


When the drawable becomes invisible, it will pause its animation. A subsequent change to
visible with `restart` set to true will restart the animation from the
first frame. If `restart` is false, the drawable will resume from the most recent
frame. If the drawable has already reached the last frame, it will then loop back to the
first frame, unless it's a one shot drawable (set through `https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#setOneShot(boolean)`),
in which case, it will stay on the last frame.

<br />

| Parameters ||
|---|---|
| `visible` | `boolean`: true if visible, false otherwise <br /> |
| `restart` | `boolean`: when visible, true to force the animation to restart from the first frame <br /> |

| Returns ||
|---|---|
| `boolean` | true if the new visibility is different than its previous state <br /> |

### start

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void start ()
```

Starts the animation from the first frame, looping if necessary. This method has no effect
if the animation is running.


**Note:** Do not call this in the
`https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle)` method of your activity, because
the `https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable` is not yet fully attached to the window.
If you want to play the animation immediately without requiring
interaction, then you might want to call it from the
`https://developer.android.com/reference/android/app/Activity#onWindowFocusChanged(boolean)` method in your
activity, which will get called when Android brings your window into
focus.

<br />

**See also:**

- `https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#isRunning()`
- `https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#stop()`

### stop

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void stop ()
```

Stops the animation at the current frame. This method has no effect if the animation is not
running.

<br />

**See also:**

- `https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#isRunning()`
- `https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable#start()`

### unscheduleSelf

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void unscheduleSelf (Runnable what)
```

Use the current `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` implementation to have this Drawable
unscheduled. Does nothing if there is no Callback attached to the
Drawable.

<br />

| Parameters ||
|---|---|
| `what` | `Runnable`: The runnable that you no longer want called. This value cannot be `null`. <br /> |

## Protected methods

### setConstantState

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void setConstantState (DrawableContainer.DrawableContainerState state)
```

<br />

<br />

| Parameters ||
|---|---|
| `state` | `DrawableContainer.DrawableContainerState`: This value cannot be `null`. <br /> |