Compartir a través de


AnimatedVectorDrawable Class

Definition

This class animates properties of a android.graphics.drawable.VectorDrawable with animations defined using android.animation.ObjectAnimator or android.animation.AnimatorSet.

[Android.Runtime.Register("android/graphics/drawable/AnimatedVectorDrawable", DoNotGenerateAcw=true)]
public class AnimatedVectorDrawable : Android.Graphics.Drawables.Drawable, Android.Graphics.Drawables.IAnimatable2, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("android/graphics/drawable/AnimatedVectorDrawable", DoNotGenerateAcw=true)>]
type AnimatedVectorDrawable = class
    inherit Drawable
    interface IAnimatable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IAnimatable2
Inheritance
AnimatedVectorDrawable
Attributes
Implements

Remarks

This class animates properties of a android.graphics.drawable.VectorDrawable with animations defined using android.animation.ObjectAnimator or android.animation.AnimatorSet.

Starting from API 25, AnimatedVectorDrawable runs on RenderThread (as opposed to on UI thread for earlier APIs). This means animations in AnimatedVectorDrawable can remain smooth even when there is heavy workload on the UI thread. Note: If the UI thread is unresponsive, RenderThread may continue animating until the UI thread is capable of pushing another frame. Therefore, it is not possible to precisely coordinate a RenderThread-enabled AnimatedVectorDrawable with UI thread animations. Additionally, android.graphics.drawable.Animatable2.AnimationCallback#onAnimationEnd(Drawable) will be called the frame after the AnimatedVectorDrawable finishes on the RenderThread.

AnimatedVectorDrawable can be defined in either three separate XML files, or one XML.

"ThreeXML"><h3>Define an AnimatedVectorDrawable in three separate XML files</h3> <ul> "VDExample"><li><h4>XML for the VectorDrawable containing properties to be animated</h4>

Animations can be performed on the animatable attributes in android.graphics.drawable.VectorDrawable. These attributes will be animated by android.animation.ObjectAnimator. The ObjectAnimator's target can be the root element, a group element or a path element. The targeted elements need to be named uniquely within the same VectorDrawable. Elements without animation do not need to be named.

Here are all the animatable attributes in android.graphics.drawable.VectorDrawable: <table border="2" align="center" cellpadding="5"> <thead> <tr> <th>Element Name</th> <th>Animatable attribute name</th> </tr> </thead> <tr> <td>&lt;vector&gt;</td> <td>alpha</td> </tr> <tr> <td rowspan="7">&lt;group&gt;</td> <td>rotation</td> </tr> <tr> <td>pivotX</td> </tr> <tr> <td>pivotY</td> </tr> <tr> <td>scaleX</td> </tr> <tr> <td>scaleY</td> </tr> <tr> <td>translateX</td> </tr> <tr> <td>translateY</td> </tr> <tr> <td rowspan="9">&lt;path&gt;</td> <td>pathData</td> </tr> <tr> <td>fillColor</td> </tr> <tr> <td>strokeColor</td> </tr> <tr> <td>strokeWidth</td> </tr> <tr> <td>strokeAlpha</td> </tr> <tr> <td>fillAlpha</td> </tr> <tr> <td>trimPathStart</td> </tr> <tr> <td>trimPathEnd</td> </tr> <tr> <td>trimPathOffset</td> </tr> <tr> <td>&lt;clip-path&gt;</td> <td>pathData</td> </tr> </table>

Below is an example of a VectorDrawable defined in vectordrawable.xml. This VectorDrawable is referred to by its file name (not including file suffix) in the AnimatedVectorDrawable XML example.

&lt;vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
                android:height=&quot;64dp&quot;
                android:width=&quot;64dp&quot;
                android:viewportHeight=&quot;600&quot;
                android:viewportWidth=&quot;600&quot; &gt;
                &lt;group
                    android:name=&quot;rotationGroup&quot;
                    android:pivotX=&quot;300.0&quot;
                    android:pivotY=&quot;300.0&quot;
                    android:rotation=&quot;45.0&quot; &gt;
                    &lt;path
                        android:name=&quot;v&quot;
                        android:fillColor=&quot;#000000&quot;
                        android:pathData=&quot;M300,70 l 0,-70 70,70 0,0 -70,70z&quot; /&gt;
                &lt;/group&gt;
            &lt;/vector&gt;

</li>

"AVDExample"><li><h4>XML for AnimatedVectorDrawable</h4>

An AnimatedVectorDrawable element has a VectorDrawable attribute, and one or more target element(s). The target element can specify its target by android:name attribute, and link the target with the proper ObjectAnimator or AnimatorSet by android:animation attribute.

The following code sample defines an AnimatedVectorDrawable. Note that the names refer to the groups and paths in the VectorDrawable XML above.

&lt;animated-vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
                android:drawable=&quot;@drawable/vectordrawable&quot; &gt;
                &lt;target
                    android:name=&quot;rotationGroup&quot;
                    android:animation=&quot;@animator/rotation&quot; /&gt;
                &lt;target
                    android:name=&quot;v&quot;
                    android:animation=&quot;@animator/path_morph&quot; /&gt;
            &lt;/animated-vector&gt;

</li>

<li><h4>XML for Animations defined using ObjectAnimator or AnimatorSet</h4>

From the previous example of AnimatedVectorDrawable, two animations were used: rotation.xml and path_morph.xml.

rotation.xml rotates the target group from 0 degree to 360 degrees over 6000ms:

&lt;objectAnimator
                android:duration=&quot;6000&quot;
                android:propertyName=&quot;rotation&quot;
                android:valueFrom=&quot;0&quot;
                android:valueTo=&quot;360&quot; /&gt;

path_morph.xml morphs the path from one shape into the other. Note that the paths must be compatible for morphing. Specifically, the paths must have the same commands, in the same order, and must have the same number of parameters for each command. It is recommended to store path strings as string resources for reuse.

&lt;set xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
                &lt;objectAnimator
                    android:duration=&quot;3000&quot;
                    android:propertyName=&quot;pathData&quot;
                    android:valueFrom=&quot;M300,70 l 0,-70 70,70 0,0 -70,70z&quot;
                    android:valueTo=&quot;M300,70 l 0,-70 70,0  0,140 -70,0 z&quot;
                    android:valueType=&quot;pathType&quot;/&gt;
            &lt;/set&gt;

</ul> "OneXML"><h3>Define an AnimatedVectorDrawable all in one XML file</h3>

Since the AAPT tool supports a new format that bundles several related XML files together, we can merge the XML files from the previous examples into one XML file:

&lt;animated-vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
                             xmlns:aapt=&quothttp://schemas.android.com/aapt&quot; &gt;
                &lt;aapt:attr name="android:drawable"&gt;
                    &lt;vector
                        android:height=&quot;64dp&quot;
                        android:width=&quot;64dp&quot;
                        android:viewportHeight=&quot;600&quot;
                        android:viewportWidth=&quot;600&quot; &gt;
                        &lt;group
                            android:name=&quot;rotationGroup&quot;
                            android:pivotX=&quot;300.0&quot;
                            android:pivotY=&quot;300.0&quot;
                            android:rotation=&quot;45.0&quot; &gt;
                            &lt;path
                                android:name=&quot;v&quot;
                                android:fillColor=&quot;#000000&quot;
                                android:pathData=&quot;M300,70 l 0,-70 70,70 0,0 -70,70z&quot; /&gt;
                        &lt;/group&gt;
                    &lt;/vector&gt;
                &lt;/aapt:attr&gt;

                &lt;target android:name=&quot;rotationGroup&quot;&gt; *
                    &lt;aapt:attr name="android:animation"&gt;
                        &lt;objectAnimator
                        android:duration=&quot;6000&quot;
                        android:propertyName=&quot;rotation&quot;
                        android:valueFrom=&quot;0&quot;
                        android:valueTo=&quot;360&quot; /&gt;
                    &lt;/aapt:attr&gt;
                &lt;/target&gt;

                &lt;target android:name=&quot;v&quot; &gt;
                    &lt;aapt:attr name="android:animation"&gt;
                        &lt;set&gt;
                            &lt;objectAnimator
                                android:duration=&quot;3000&quot;
                                android:propertyName=&quot;pathData&quot;
                                android:valueFrom=&quot;M300,70 l 0,-70 70,70 0,0 -70,70z&quot;
                                android:valueTo=&quot;M300,70 l 0,-70 70,0  0,140 -70,0 z&quot;
                                android:valueType=&quot;pathType&quot;/&gt;
                        &lt;/set&gt;
                    &lt;/aapt:attr&gt;
                 &lt;/target&gt;
            &lt;/animated-vector&gt;

Java documentation for android.graphics.drawable.AnimatedVectorDrawable.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

AnimatedVectorDrawable()
AnimatedVectorDrawable(IntPtr, JniHandleOwnership)

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

Properties

Alpha

Gets the current alpha value for the drawable.

(Inherited from Drawable)
AutoMirrored

Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. -or- Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left).

(Inherited from Drawable)
Bounds

Return the drawable's bounds Rect. -or- Specify a bounding rectangle for the Drawable.

(Inherited from Drawable)
Callback

Return the current Callback implementation attached to this Drawable.

(Inherited from Drawable)
ChangingConfigurations

Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. -or- Set a mask of the configuration parameters for which this drawable may change, requiring that it be re-created.

(Inherited from Drawable)
Class

Returns the runtime class of this Object.

(Inherited from Object)
ColorFilter

Returns the current color filter, or null if none set.

(Inherited from Drawable)
Current (Inherited from Drawable)
DirtyBounds

Return the drawable's dirty bounds Rect.

(Inherited from Drawable)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
HasFocusStateSpecified

Indicates whether this drawable has at least one state spec explicitly specifying android.R.attr#state_focused.

(Inherited from Drawable)
IntrinsicHeight

Returns the drawable's intrinsic height.

(Inherited from Drawable)
IntrinsicWidth

Returns the drawable's intrinsic width.

(Inherited from Drawable)
IsFilterBitmap (Inherited from Drawable)
IsProjected

Whether this drawable requests projection.

(Inherited from Drawable)
IsRunning

Indicates whether the animation is running.

IsStateful

Indicates whether this drawable will change its appearance based on state.

(Inherited from Drawable)
IsVisible (Inherited from Drawable)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LayoutDirection

Returns the resolved layout direction for this Drawable.

(Inherited from Drawable)
Level

Retrieve the current level.

(Inherited from Drawable)
MinimumHeight

Returns the minimum height suggested by this Drawable.

(Inherited from Drawable)
MinimumWidth

Returns the minimum width suggested by this Drawable.

(Inherited from Drawable)
Opacity

Return the opacity/transparency of this Drawable.

OpticalInsets

Return in insets the layout insets suggested by this Drawable for use with alignment operations during layout.

(Inherited from Drawable)
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

TransparentRegion

Returns a Region representing the part of the Drawable that is completely transparent.

(Inherited from Drawable)

Methods

ApplyTheme(Resources+Theme)

Applies the specified theme to this Drawable and its children.

(Inherited from Drawable)
CanApplyTheme() (Inherited from Drawable)
ClearAnimationCallbacks()
ClearColorFilter()

Removes the color filter for this drawable.

(Inherited from Drawable)
Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CopyBounds()

Return a copy of the drawable's bounds in a new Rect.

(Inherited from Drawable)
CopyBounds(Rect)

Return a copy of the drawable's bounds in the specified Rect (allocated by the caller).

(Inherited from Drawable)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Draw(Canvas)

Draws the AnimatedVectorDrawable into the given canvas.

Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetConstantState()

Return a ConstantState instance that holds the shared state of this Drawable.

(Inherited from Drawable)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetHotspotBounds(Rect)

Populates outRect with the hotspot bounds.

(Inherited from Drawable)
GetOutline(Outline)

Called to get the drawable to populate the Outline that defines its drawing area.

(Inherited from Drawable)
GetPadding(Rect)

Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds.

(Inherited from Drawable)
GetState()

Describes the current state, as a union of primitve states, such as android.R.attr#state_focused, android.R.attr#state_selected, etc.

(Inherited from Drawable)
Inflate(Resources, XmlReader, IAttributeSet, Resources+Theme)

Inflate this Drawable from an XML resource.

(Inherited from Drawable)
Inflate(Resources, XmlReader, IAttributeSet)

Inflate this Drawable from an XML resource.

(Inherited from Drawable)
InflateAsync(Resources, XmlReader, IAttributeSet, Resources+Theme) (Inherited from Drawable)
InflateAsync(Resources, XmlReader, IAttributeSet) (Inherited from Drawable)
InvalidateSelf()

Use the current Callback implementation to have this Drawable redrawn.

(Inherited from Drawable)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
JumpToCurrentState()

If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.

(Inherited from Drawable)
Mutate()

Make this drawable mutable.

(Inherited from Drawable)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
OnBoundsChange(Rect)

Override this in your subclass to change appearance if you vary based on the bounds.

(Inherited from Drawable)
OnLayoutDirectionChanged(Int32)

Called when the drawable's resolved layout direction changes.

(Inherited from Drawable)
OnLevelChange(Int32)

Override this in your subclass to change appearance if you vary based on level.

(Inherited from Drawable)
OnStateChange(Int32[])

Override this in your subclass to change appearance if you recognize the specified state.

(Inherited from Drawable)
RegisterAnimationCallback(Animatable2AnimationCallback)
Reset()

Resets the AnimatedVectorDrawable to the start state as specified in the animators.

ScheduleSelf(Action, Int64) (Inherited from Drawable)
ScheduleSelf(IRunnable, Int64)

Use the current Callback implementation to have this Drawable scheduled.

(Inherited from Drawable)
SetAlpha(Int32)

Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.

SetBounds(Int32, Int32, Int32, Int32)

Specify a bounding rectangle for the Drawable.

(Inherited from Drawable)
SetCallback(Drawable+ICallback)

Bind a Callback object to this Drawable.

(Inherited from Drawable)
SetColorFilter(Color, PorterDuff+Mode)

Specify a color and Porter-Duff mode to be the color filter for this drawable.

(Inherited from Drawable)
SetColorFilter(ColorFilter)

Specify an optional color filter for the drawable.

SetDither(Boolean)

Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component.

(Inherited from Drawable)
SetFilterBitmap(Boolean)

Set to true to have the drawable filter its bitmaps with bilinear sampling when they are scaled or rotated.

(Inherited from Drawable)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetHotspot(Single, Single)

Specifies the hotspot's location within the drawable.

(Inherited from Drawable)
SetHotspotBounds(Int32, Int32, Int32, Int32)

Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds.

(Inherited from Drawable)
SetLayoutDirection(LayoutDirection)

Set the layout direction for this drawable.

(Inherited from Drawable)
SetLevel(Int32)

Specify the level for the drawable.

(Inherited from Drawable)
SetState(Int32[])

Specify a set of states for the drawable.

(Inherited from Drawable)
SetTint(Int32)

Specifies tint color for this drawable.

(Inherited from Drawable)
SetTintBlendMode(BlendMode)

Specifies a tint blending mode for this drawable.

(Inherited from Drawable)
SetTintList(ColorStateList)

Specifies tint color for this drawable as a color state list.

(Inherited from Drawable)
SetTintMode(PorterDuff+Mode)

Specifies a tint blending mode for this drawable.

(Inherited from Drawable)
SetVisible(Boolean, Boolean)

Set whether this Drawable is visible.

(Inherited from Drawable)
Start()

Starts the drawable's animation.

Stop()

Stops the drawable's animation.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterAnimationCallback(Animatable2AnimationCallback)
UnregisterFromRuntime() (Inherited from Object)
UnscheduleSelf(Action) (Inherited from Drawable)
UnscheduleSelf(IRunnable)

Use the current Callback implementation to have this Drawable unscheduled.

(Inherited from Drawable)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to