다음을 통해 공유


VectorDrawable Class

Definition

This lets you create a drawable based on an XML vector graphic.

[Android.Runtime.Register("android/graphics/drawable/VectorDrawable", DoNotGenerateAcw=true)]
public class VectorDrawable : Android.Graphics.Drawables.Drawable
[<Android.Runtime.Register("android/graphics/drawable/VectorDrawable", DoNotGenerateAcw=true)>]
type VectorDrawable = class
    inherit Drawable
Inheritance
VectorDrawable
Attributes

Remarks

This lets you create a drawable based on an XML vector graphic. <p/> <strong>Note:</strong> To optimize for the re-drawing performance, one bitmap cache is created for each VectorDrawable. Therefore, referring to the same VectorDrawable means sharing the same bitmap cache. If these references don't agree upon on the same size, the bitmap will be recreated and redrawn every time size is changed. In other words, if a VectorDrawable is used for different sizes, it is more efficient to create multiple VectorDrawables, one for each size. <p/> VectorDrawable can be defined in an XML file with the &lt;vector> element. <p/> The vector drawable has the following elements: <p/> <dt>&lt;vector></dt> <dl> <dd>Used to define a vector drawable <dl> <dt>android:name</dt> <dd>Defines the name of this vector drawable.</dd> <dt>android:width</dt> <dd>Used to define the intrinsic width of the drawable. This supports all the dimension units, normally specified with dp.</dd> <dt>android:height</dt> <dd>Used to define the intrinsic height of the drawable. This supports all the dimension units, normally specified with dp.</dd> <dt>android:viewportWidth</dt> <dd>Used to define the width of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.</dd> <dt>android:viewportHeight</dt> <dd>Used to define the height of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on.</dd> <dt>android:tint</dt> <dd>The color to apply to the drawable as a tint. By default, no tint is applied.</dd> <dt>android:tintMode</dt> <dd>The Porter-Duff blending mode for the tint color. Default is src_in.</dd> <dt>android:autoMirrored</dt> <dd>Indicates if the drawable needs to be mirrored when its layout direction is RTL (right-to-left). Default is false.</dd> <dt>android:alpha</dt> <dd>The opacity of this drawable. Default is 1.0.</dd> </dl></dd> </dl>

<dl> <dt>&lt;group></dt> <dd>Defines a group of paths or subgroups, plus transformation information. The transformations are defined in the same coordinates as the viewport. And the transformations are applied in the order of scale, rotate then translate. <dl> <dt>android:name</dt> <dd>Defines the name of the group.</dd> <dt>android:rotation</dt> <dd>The degrees of rotation of the group. Default is 0.</dd> <dt>android:pivotX</dt> <dd>The X coordinate of the pivot for the scale and rotation of the group. This is defined in the viewport space. Default is 0.</dd> <dt>android:pivotY</dt> <dd>The Y coordinate of the pivot for the scale and rotation of the group. This is defined in the viewport space. Default is 0.</dd> <dt>android:scaleX</dt> <dd>The amount of scale on the X Coordinate. Default is 1.</dd> <dt>android:scaleY</dt> <dd>The amount of scale on the Y coordinate. Default is 1.</dd> <dt>android:translateX</dt> <dd>The amount of translation on the X coordinate. This is defined in the viewport space. Default is 0.</dd> <dt>android:translateY</dt> <dd>The amount of translation on the Y coordinate. This is defined in the viewport space. Default is 0.</dd> </dl></dd> </dl>

<dl> <dt>&lt;path></dt> <dd>Defines paths to be drawn. <dl> <dt>android:name</dt> <dd>Defines the name of the path.</dd> <dt>android:pathData</dt> <dd>Defines path data using exactly same format as "d" attribute in the SVG's path data. This is defined in the viewport space.</dd> <dt>android:fillColor</dt> <dd>Specifies the color used to fill the path. May be a color or, for SDK 24+, a color state list or a gradient color (See android.R.styleable#GradientColor and android.R.styleable#GradientColorItem). If this property is animated, any value set by the animation will override the original value. No path fill is drawn if this property is not specified.</dd> <dt>android:strokeColor</dt> <dd>Specifies the color used to draw the path outline. May be a color or, for SDK 24+, a color state list or a gradient color (See android.R.styleable#GradientColor and android.R.styleable#GradientColorItem). If this property is animated, any value set by the animation will override the original value. No path outline is drawn if this property is not specified.</dd> <dt>android:strokeWidth</dt> <dd>The width a path stroke. Default is 0.</dd> <dt>android:strokeAlpha</dt> <dd>The opacity of a path stroke. Default is 1.</dd> <dt>android:fillAlpha</dt> <dd>The opacity to fill the path with. Default is 1.</dd> <dt>android:trimPathStart</dt> <dd>The fraction of the path to trim from the start, in the range from 0 to 1. Default is 0.</dd> <dt>android:trimPathEnd</dt> <dd>The fraction of the path to trim from the end, in the range from 0 to 1. Default is 1.</dd> <dt>android:trimPathOffset</dt> <dd>Shift trim region (allows showed region to include the start and end), in the range from 0 to 1. Default is 0.</dd> <dt>android:strokeLineCap</dt> <dd>Sets the linecap for a stroked path: butt, round, square. Default is butt.</dd> <dt>android:strokeLineJoin</dt> <dd>Sets the lineJoin for a stroked path: miter,round,bevel. Default is miter.</dd> <dt>android:strokeMiterLimit</dt> <dd>Sets the Miter limit for a stroked path. Default is 4.</dd> <dt>android:fillType</dt> <dd>For SDK 24+, sets the fillType for a path. The types can be either "evenOdd" or "nonZero". They behave the same as SVG's "fill-rule" properties. Default is nonZero. For more details, see FillRuleProperty</dd> </dl></dd>

</dl>

<dl> <dt>&lt;clip-path></dt> <dd>Defines path to be the current clip. Note that the clip path only apply to the current group and its children. <dl> <dt>android:name</dt> <dd>Defines the name of the clip path.</dd> <dd>Animatable : No.</dd> <dt>android:pathData</dt> <dd>Defines clip path using the same format as "d" attribute in the SVG's path data.</dd> <dd>Animatable : Yes.</dd> </dl></dd> </dl> <li>Here is a simple VectorDrawable in this vectordrawable.xml file.

&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> <h4>Gradient support</h4> We support 3 types of gradients: android.graphics.LinearGradient, android.graphics.RadialGradient, or android.graphics.SweepGradient. <p/> And we support all of 3 types of tile modes android.graphics.Shader.TileMode: CLAMP, REPEAT, MIRROR. <p/> All of the attributes are listed in android.R.styleable#GradientColor. Note that different attributes are relevant for different types of gradient. <table border="2" align="center" cellpadding="5"> <thead> <tr> <th>LinearGradient</th> <th>RadialGradient</th> <th>SweepGradient</th> </tr> </thead> <tr> <td>startColor </td> <td>startColor</td> <td>startColor</td> </tr> <tr> <td>centerColor</td> <td>centerColor</td> <td>centerColor</td> </tr> <tr> <td>endColor</td> <td>endColor</td> <td>endColor</td> </tr> <tr> <td>type</td> <td>type</td> <td>type</td> </tr> <tr> <td>tileMode</td> <td>tileMode</td> <td>tileMode</td> </tr> <tr> <td>startX</td> <td>centerX</td> <td>centerX</td> </tr> <tr> <td>startY</td> <td>centerY</td> <td>centerY</td> </tr> <tr> <td>endX</td> <td>gradientRadius</td> <td></td> </tr> <tr> <td>endY</td> <td></td> <td></td> </tr> </table> <p/> Also note that if any color item android.R.styleable#GradientColorItem is defined, then startColor, centerColor and endColor will be ignored. <p/> See more details in android.R.styleable#GradientColor and android.R.styleable#GradientColorItem. <p/> Here is a simple example that defines a linear gradient.

&lt;gradient xmlns:android="http://schemas.android.com/apk/res/android"
                android:startColor="?android:attr/colorPrimary"
                android:endColor="?android:attr/colorControlActivated"
                android:centerColor="#f00"
                android:startX="0"
                android:startY="0"
                android:endX="100"
                android:endY="100"
                android:type="linear"&gt;
            &lt;/gradient&gt;

And here is a simple example that defines a radial gradient using color items.

&lt;gradient xmlns:android="http://schemas.android.com/apk/res/android"
                android:centerX="300"
                android:centerY="300"
                android:gradientRadius="100"
                android:type="radial"&gt;
                &lt;item android:offset="0.1" android:color="#0ff"/&gt;
                &lt;item android:offset="0.4" android:color="#fff"/&gt;
                &lt;item android:offset="0.9" android:color="#ff0"/&gt;
            &lt;/gradient&gt;

Java documentation for android.graphics.drawable.VectorDrawable.

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

VectorDrawable()

The one constructor to rule them all.

VectorDrawable(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)
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)
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)

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

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)
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)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
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