AnimatedVectorDrawableCompat

public class AnimatedVectorDrawableCompat
extends Drawable implements Animatable2Compat

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat


For API 24 and above, this class is delegating to the framework's AnimatedVectorDrawable. For older API version, this class uses ObjectAnimator and AnimatorSet to animate the properties of a VectorDrawableCompat to create an animated drawable.

AnimatedVectorDrawableCompat are defined in the same XML format as AnimatedVectorDrawable.

Here are all the animatable attributes in VectorDrawableCompat:

Element Name Animatable attribute name
<vector> alpha
<group> rotation
pivotX
pivotY
scaleX
scaleY
translateX
translateY
<path> fillColor
pathData
strokeColor
strokeWidth
strokeAlpha
fillAlpha
trimPathStart
trimPathEnd
trimPathOffset

You can always create a AnimatedVectorDrawableCompat object and use it as a Drawable by the Java API. In order to refer to AnimatedVectorDrawableCompat inside a XML file, you can use app:srcCompat attribute in AppCompat library's ImageButton or ImageView.

Note that the animation in AnimatedVectorDrawableCompat now can support the following features:

  • Path Morphing (PathType evaluator). This is used for morphing one path into another.
  • Path Interpolation. This is used to defined a flexible interpolator (represented as a path) instead of the system defined ones like LinearInterpolator.
  • Animating 2 values in one ObjectAnimator according to one path's X value and Y value. One usage is moving one object in both X and Y dimensions along an path.

Summary

Public methods

void applyTheme(Resources.Theme t)
boolean canApplyTheme()
void clearAnimationCallbacks()

Removes all existing animation callbacks.

static void clearAnimationCallbacks(Drawable dr)

Utility function to clear animation callbacks from Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable().

void clearColorFilter()
static AnimatedVectorDrawableCompat create(Context context, int resId)

Create a AnimatedVectorDrawableCompat object.

static AnimatedVectorDrawableCompat createFromXmlInner(Context context, Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)

Create a AnimatedVectorDrawableCompat from inside an XML document using an optional Resources.Theme.

void draw(Canvas canvas)
int getAlpha()
int getChangingConfigurations()
ColorFilter getColorFilter()
Drawable.ConstantState getConstantState()

Note that we don't support constant state when SDK < 24.

Drawable getCurrent()
int getIntrinsicHeight()
int getIntrinsicWidth()
int getMinimumHeight()
int getMinimumWidth()
int getOpacity()
boolean getPadding(Rect padding)
int[] getState()
Region getTransparentRegion()
void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
void inflate(Resources res, XmlPullParser parser, AttributeSet attrs)
boolean isAutoMirrored()
boolean isRunning()
boolean isStateful()
void jumpToCurrentState()
Drawable mutate()

mutate() will be effective only if the getConstantState() is returning non-null.

void registerAnimationCallback(