Google is committed to advancing racial equity for Black communities. See how.

SeekableAnimatedVectorDrawable

open class SeekableAnimatedVectorDrawable : Drawable, Animatable
kotlin.Any
   ↳ android.graphics.drawable.Drawable
   ↳ androidx.vectordrawable.graphics.drawable.SeekableAnimatedVectorDrawable

This class animates properties of a VectorDrawableCompat with animations defined using ObjectAnimator or AnimatorSet.

SeekableAnimatedVectorDrawable is defined in the same XML format as android.graphics.drawable.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 SeekableAnimatedVectorDrawable object and use it as a Drawable by the Java API. In order to refer to SeekableAnimatedVectorDrawable inside an XML file, you can use app:srcCompat attribute in AppCompat library's ImageButton or ImageView.

SeekableAnimatedVectorDrawable supports the following features too:

  • 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.

Unlike AnimatedVectorDrawableCompat, this class does not delegate to the platform android.graphics.drawable.AnimatedVectorDrawable on any API levels.

Summary

Nested classes
abstract

Abstract class for animation callback.

Public methods
open Unit
applyTheme(@NonNull t: Theme)

open Boolean

open Unit

Removes all existing animation callbacks.

open static SeekableAnimatedVectorDrawable?
create(@NonNull context: Context, @DrawableRes resId: Int)

Create a SeekableAnimatedVectorDrawable object.

open static SeekableAnimatedVectorDrawable
createFromXmlInner(@NonNull r: Resources, @NonNull parser: XmlPullParser, @NonNull attrs: AttributeSet, @Nullable theme: Theme?)

Create a SeekableAnimatedVectorDrawable from inside an XML document using an optional Theme.

open Unit
draw(@NonNull canvas: Canvas)

open Int

open Int

open ColorFilter?

open ConstantState?

open Long

Returns the milliseconds elapsed since the start of the animation.

open Int

open Int

open Int

open Long

Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating.

open Unit
inflate(@NonNull res: Resources, @NonNull parser: XmlPullParser, @NonNull attrs: AttributeSet, @Nullable theme: Theme?)

open Unit
inflate(@NonNull res: Resources, @NonNull parser: XmlPullParser, @NonNull attrs: AttributeSet)

open Boolean

open Boolean

Returns whether the animation is currently in a paused state.

open Boolean

Returns whether the animation is running (has started and not yet ended).

open Boolean

open Drawable

mutate() is not supported.

open Unit

Pauses a running animation.

open Unit

Adds a callback to listen to the animation events.

open Unit

Resumes a paused animation.

open Unit
setAlpha(@IntRange(0, 255) alpha: Int)

open Unit

open Unit
setColorFilter(@Nullable colorFilter: ColorFilter?)

open Unit
setCurrentPlayTime(@IntRange(0) playTime: Long)

Sets the position of the animation to the specified point in time.

open Unit
setTint(@ColorInt tint: Int)

open Unit
setTintList(@Nullable tint: ColorStateList?)

open Unit
setTintMode(@Nullable tintMode: Mode?)

open Boolean
setVisible(visible: Boolean, restart: Boolean)

open Unit

open Unit

open Boolean

Removes the specified animation callback.

Protected methods
open Unit
onBoundsChange(@NonNull bounds: Rect)

open Boolean

open Boolean
onStateChange(@NonNull state: IntArray)

Public methods

applyTheme

open fun applyTheme(@NonNull t: Theme): Unit

canApplyTheme

open fun canApplyTheme(): Boolean

clearAnimationCallbacks

open fun clearAnimationCallbacks(): Unit

Removes all existing animation callbacks.

create

@Nullable open static fun create(
    @NonNull context: Context,
    @DrawableRes resId: Int
): SeekableAnimatedVectorDrawable?

Create a SeekableAnimatedVectorDrawable object.

Parameters
context Context: the context for creating the animators.
resId Int: the resource ID for SeekableAnimatedVectorDrawable object.
Return
SeekableAnimatedVectorDrawable? a new SeekableAnimatedVectorDrawable or null if parsing error is found.

createFromXmlInner

@NonNull open static fun createFromXmlInner(
    @NonNull r: Resources,
    @NonNull parser: XmlPullParser,
    @NonNull attrs: AttributeSet,
    @Nullable theme: Theme?
): SeekableAnimatedVectorDrawable

Create a SeekableAnimatedVectorDrawable from inside an XML document using an optional Theme. Called on a parser positioned at a tag in an XML document, tries to create a Drawable from that tag. Returns null if the tag is not a valid drawable.

draw

open fun draw(@NonNull canvas: Canvas): Unit

getAlpha

@IntRange(0, 255) open fun getAlpha(): Int

getChangingConfigurations

open fun getChangingConfigurations(): Int

getColorFilter

@Nullable open fun getColorFilter(): ColorFilter?

getConstantState

@Nullable open fun getConstantState(): ConstantState?

getCurrentPlayTime

@IntRange(0) open fun getCurrentPlayTime(): Long

Returns the milliseconds elapsed since the start of the animation.

For ongoing animations, this method returns the current progress of the animation in terms of play time. For an animation that has not yet been started: if the animation has been seeked to a certain time via setCurrentPlayTime(long), the seeked play time will be returned; otherwise, this method will return 0.

Return
Long the current position in time of the animation in milliseconds

getIntrinsicHeight

open fun getIntrinsicHeight(): Int

getIntrinsicWidth

open fun getIntrinsicWidth(): Int

getOpacity

open fun getOpacity(): Int

Deprecated: This method is no longer used in graphics optimizations

Return
Int The opacity class of the Drawable.

getTotalDuration

open fun getTotalDuration(): Long

Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating. Return Animator#DURATION_INFINITE if the duration is infinite.

Return
Long Total time the animation takes to finish, starting from the time start() is called. Animator#DURATION_INFINITE if the animation or any of the child animations repeats infinite times.

inflate

open fun inflate(
    @NonNull res: Resources,
    @NonNull parser: XmlPullParser,
    @NonNull attrs: AttributeSet,
    @Nullable theme: Theme?
): Unit

inflate

open fun inflate(
    @NonNull res: Resources,
    @NonNull parser: XmlPullParser,
    @NonNull attrs: AttributeSet
): Unit

isAutoMirrored

open fun isAutoMirrored(): Boolean

isPaused

open fun isPaused(): Boolean

Returns whether the animation is currently in a paused state.

Return
Boolean true if the animation is paused.

isRunning

open fun isRunning(): Boolean

Returns whether the animation is running (has started and not yet ended).

Return
Boolean true if the animation is running.

isStateful

open fun isStateful(): Boolean

mutate

@NonNull open fun mutate(): Drawable

mutate() is not supported. This method simply returns this.

pause

open fun pause(): Unit

Pauses a running animation. This method should only be called on the same thread on which the animation was started. If the animation has not yet been started or has since ended, then the call is ignored. Paused animations can be resumed by calling resume().

registerAnimationCallback

open fun registerAnimationCallback(@NonNull callback: SeekableAnimatedVectorDrawable.AnimationCallback): Unit

Adds a callback to listen to the animation events.

Parameters
callback SeekableAnimatedVectorDrawable.AnimationCallback: Callback to add.

resume

open fun resume(): Unit

Resumes a paused animation. The animation resumes from where it left off when it was paused. This method should only be called on the same thread on which the animation was started. Calls will be ignored if this SeekableAnimatedVectorDrawable is not currently paused.

setAlpha

open fun setAlpha(@IntRange(0, 255) alpha: Int): Unit

setAutoMirrored

open fun setAutoMirrored(mirrored: Boolean): Unit

setColorFilter

open fun setColorFilter(@Nullable colorFilter: ColorFilter?): Unit

setCurrentPlayTime

open fun setCurrentPlayTime(@IntRange(0) playTime: Long): Unit

Sets the position of the animation to the specified point in time. This time should be between 0 and the total duration of the animation, including any repetition. If the animation has not yet been started, then it will not advance forward after it is set to this time; it will simply set the time to this value and perform any appropriate actions based on that time. If the animation is already running, then setCurrentPlayTime() will set the current playing time to this value and continue playing from that point.

Parameters
playTime Long: The time, in milliseconds, to which the animation is advanced or rewound. Unless the animation is reversing, the playtime is considered the time since the end of the start delay of the AnimatorSet in a forward playing direction.

setTint

open fun setTint(@ColorInt tint: Int): Unit

setTintList

open fun setTintList(@Nullable tint: ColorStateList?): Unit

setTintMode

open fun setTintMode(@Nullable tintMode: Mode?): Unit

setVisible

open fun setVisible(
    visible: Boolean,
    restart: Boolean
): Boolean

start

open fun start(): Unit

stop

open fun stop(): Unit

unregisterAnimationCallback

open fun unregisterAnimationCallback(@NonNull callback: SeekableAnimatedVectorDrawable.AnimationCallback): Boolean

Removes the specified animation callback.

Parameters
callback SeekableAnimatedVectorDrawable.AnimationCallback: Callback to remove.
Return
Boolean false if callback didn't exist in the call back list, or true if callback has been removed successfully.

Protected methods

onBoundsChange

protected open fun onBoundsChange(@NonNull bounds: Rect): Unit

onLevelChange

protected open fun onLevelChange(level: Int): Boolean

onStateChange

protected open fun onStateChange(@NonNull state: IntArray): Boolean