Most visited

Recently visited

AnimatedVectorDrawableCompat

public class AnimatedVectorDrawableCompat
extends Drawable implements Animatable

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.support.graphics.drawable.AnimatedVectorDrawableCompat


对于API 23及以上版本,此类将委托给框架的AnimatedVectorDrawable 对于老版本的API,这个类使用ObjectAnimatorAnimatorSet到一个动画的属性VectorDrawableCompat创建动画绘制。

AnimatedVectorDrawableCompat使用与 AnimatedVectorDrawable相同的XML格式 AnimatedVectorDrawable

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.

Summary

Public methods

void applyTheme(Resources.Theme t)

将指定的主题应用于此Drawable及其子项。

boolean canApplyTheme()
void clearColorFilter()

移除该drawable的颜色过滤器。

static AnimatedVectorDrawableCompat create(Context context, int resId)

创建一个AnimatedVectorDrawableCompat对象。

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

使用可选的 Resources.Theme从XML文档中创建AnimatedVectorDrawableCompat。

void draw(Canvas canvas)

在其边界(通过setBounds设置)中绘制,考虑可选效果,如alpha(通过setAlpha设置)和color filter(通过setColorFilter设置)。

int getAlpha()

获取drawable的当前alpha值。

int getChangingConfigurations()

返回此drawable可能更改的配置参数的掩码,要求重新创建它。

ColorFilter getColorFilter()

如果没有设置,则返回当前的颜色过滤器或 null

Drawable.ConstantState getConstantState()

返回保存此Drawable的共享状态的Drawable.ConstantState实例。 请注意 ,当SDK <23时,我们不支持常量状态。

Drawable getCurrent()
int getIntrinsicHeight()

返回drawable的内在高度。

int getIntrinsicWidth()

返回drawable的内部宽度。

int getLayoutDirection()

返回此Drawable的已解析布局方向。

int getMinimumHeight()

返回此Drawable建议的最小高度。

int getMinimumWidth()

返回此Drawable建议的最小宽度。

int getOpacity()

返回此Drawable的不透明度/透明度。

boolean getPadding(Rect padding)

返回填充此Drawable建议的插入内容以将内容放入drawable的边界内。

int[] getState()

描述了当前状态,如primitve状态的联合,如 state_focusedstate_selected

Region getTransparentRegion()

返回表示完全透明的Drawable部分的区域。

void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)

从可选的由主题设计的XML资源中扩展此Drawable。

void inflate(Resources res, XmlPullParser parser, AttributeSet attrs)

从XML资源膨胀此Drawable。

boolean isAutoMirrored()

当它的布局方向是从右到左的RTL时,告诉它是否自动镜像。

boolean isRunning()

指示动画是否正在运行。

boolean isStateful()

指示此drawable是否会根据状态更改其外观。

void jumpToCurrentState()

如果此Drawable确实在状态之间转换动画,请求它立即跳转到当前状态并跳过任何活动动画。

Drawable mutate()

使这个drawable可变。

void setAlpha(int alpha)

为drawable指定一个alpha值。

void setAutoMirrored(boolean mirrored)

设置当其布局方向为RTL(从右到左)时,此Drawable是否自动镜像。

void setChangingConfigurations(int configs)

设置该drawable可能更改的配置参数的掩码,要求重新创建它。

void setColorFilter(ColorFilter colorFilter)

为绘图指定一个可选的颜色过滤器。

void setColorFilter(int color, PorterDuff.Mode mode)

指定一个颜色和Porter-Duff模式作为该drawable的颜色过滤器。

void setFilterBitmap(boolean filter)

设置为true时,在缩放或旋转时使可绘制滤镜具有双线性采样的位图。

void setHotspot(float x, float y)

指定可绘制内的热点位置。

void setHotspotBounds(int left, int top, int right, int bottom)

设置热点受限的边界,如果它们应该与可绘制边界不同。

boolean setState(int[] stateSet)

为drawable指定一组状态。

void setTint(int tint)

指定该drawable的色调颜色。

void setTintList(ColorStateList tint)

指定该drawable的色彩颜色作为颜色状态列表。

void setTintMode(PorterDuff.Mode tintMode)

指定该drawable的色调混合模式。

boolean setVisible(boolean visible, boolean restart)

设置此Drawable是否可见。

void start()

开始drawable的动画。

void stop()

停止绘图的动画。

Protected methods

void onBoundsChange(Rect bounds)

如果您根据边界而变化,请在您的子类中覆盖此内容以更改外观。

boolean onLevelChange(int level)

如果您根据级别而变化,请在您的子类中覆盖此内容以更改外观。

boolean onStateChange(int[] state)

如果您认识到指定的状态,请在您的子类中覆盖此内容以更改外观。

Inherited methods

From class android.graphics.drawable.Drawable
From class java.lang.Object
From interface android.graphics.drawable.Animatable

Public methods

applyTheme

void applyTheme (Resources.Theme t)

将指定的主题应用于此Drawable及其子项。

Parameters
t Resources.Theme: the theme to apply

canApplyTheme

boolean canApplyTheme ()

Returns
boolean

clearColorFilter

void clearColorFilter ()

移除该drawable的颜色过滤器。

create

AnimatedVectorDrawableCompat create (Context context, 
                int resId)

创建一个AnimatedVectorDrawableCompat对象。

Parameters
context Context: the context for creating the animators.
resId int: the resource ID for AnimatedVectorDrawableCompat object.
Returns
AnimatedVectorDrawableCompat a new AnimatedVectorDrawableCompat or null if parsing error is found.

createFromXmlInner

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

使用可选的Resources.Theme从XML文档中创建AnimatedVectorDrawableCompat。 调用位于XML文档标签中的解析器,尝试从该标签创建Drawable。 如果标签不是有效的drawable,则返回null

Parameters
context Context
r Resources
parser XmlPullParser
attrs AttributeSet
theme Resources.Theme
Returns
AnimatedVectorDrawableCompat
Throws
XmlPullParserException
IOException

draw

void draw (Canvas canvas)

在其边界(通过setBounds设置)中绘制,考虑可选效果,如alpha(通过setAlpha设置)和color filter(通过setColorFilter设置)。

Parameters
canvas Canvas: The canvas to draw into

getAlpha

int getAlpha ()

获取drawable的当前alpha值。 0表示完全透明,255表示完全不透明。 该方法由Drawable子类实现,返回的值特定于该类如何处理alpha。 如果该类未覆盖此方法以返回特定于其使用alpha的值,则默认返回值为255。

Returns
int

getChangingConfigurations

int getChangingConfigurations ()

返回此drawable可能更改的配置参数的掩码,要求重新创建它。 默认实现返回setChangingConfigurations(int)或默认情况下提供的任何值。 子类可以将其扩展到它们所拥有的任何其他drawable的变化配置中或其中。

Returns
int Returns a mask of the changing configuration parameters, as defined by ActivityInfo.

getColorFilter

ColorFilter getColorFilter ()

如果没有设置,则返回当前的颜色过滤器或 null

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

getConstantState

Drawable.ConstantState getConstantState ()

返回保存此Drawable的共享状态的Drawable.ConstantState实例。 请注意 ,当SDK <23时,我们不支持常量状态。请确保在使用它之前检查返回值。

Returns
Drawable.ConstantState The ConstantState associated to that Drawable.

getCurrent

Drawable getCurrent ()

Returns
Drawable The current drawable that will be used by this drawable. For simple drawables, this is just the drawable itself. For drawables that change state like StateListDrawable and LevelListDrawable this will be the child drawable currently in use.

getIntrinsicHeight

int getIntrinsicHeight ()

返回drawable的内在高度。

固有高度是可拉伸的布局高度,包括任何固有的填充。 如果drawable没有固有的高度,例如纯色,则此方法返回-1。

Returns
int the intrinsic height, or -1 if no intrinsic height

getIntrinsicWidth

int getIntrinsicWidth ()

返回drawable的内部宽度。

固有宽度是可展开的布局的宽度,包括任何固有的填充。 如果drawable没有固有的宽度,例如纯色,则此方法返回-1。

Returns
int the intrinsic width, or -1 if no intrinsic width

getLayoutDirection

int getLayoutDirection ()

返回此Drawable的已解析布局方向。

Returns
int One of LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL

getMinimumHeight

int getMinimumHeight ()

返回此Drawable建议的最小高度。 如果一个View使用这个Drawable作为背景,那么建议View使用至少这个值来表示它的高度。 (在某些情况下这是不可能的。)这个值应该包含任何填充。

Returns
int The minimum height suggested by this Drawable. If this Drawable doesn't have a suggested minimum height, 0 is returned.

getMinimumWidth

int getMinimumWidth ()

返回此Drawable建议的最小宽度。 如果一个View使用这个Drawable作为背景,那么建议View至少使用这个值来表示它的宽度。 (在某些情况下这是不可能的。)这个值应该包含任何填充。

Returns
int The minimum width suggested by this Drawable. If this Drawable doesn't have a suggested minimum width, 0 is returned.

getOpacity

int getOpacity ()

返回此Drawable的不透明度/透明度。 返回的值是在抽象格式常数之一PixelFormatUNKNOWNTRANSLUCENTTRANSPARENT ,或OPAQUE

OPAQUE drawable是一个绘制所有内容的范围,完全覆盖drawable后面的所有内容。 一个TRANSPARENT drawable是一个在其范围内没有绘制任何东西的图形,允许它后面的所有东西都显示出来。 TRANSLUCENT drawable是任何其他状态中的drawable,drawable将绘制其边界内的一些内容,但不是全部内容,并且至少drawable后面的某些内容将可见。 如果无法确定可绘制内容的可见性,则最安全/最佳返回值为TRANSLUCENT。

一般而言,Drawable应该尽可能保守并且返回值。 例如,如果它包含多个子drawable,并且一次只显示其中一个,如果只有一个子项是TRANSLUCENT,而其他子项是OPAQUE,则应返回TRANSLUCENT。 您可以使用方法resolveOpacity(int, int)将两个不透明度标准减少为适当的单个输出。

请注意,返回的值不一定会考虑客户端通过setAlpha(int)setColorFilter(ColorFilter)方法应用的自定义alpha或颜色过滤器。 一些子类,比如BitmapDrawableColorDrawable ,并GradientDrawable ,对价值做账setAlpha(int) ,但总的行为是依赖于子类实现的。

Returns
int int The opacity class of the Drawable.

getPadding

boolean getPadding (Rect padding)

返回填充此Drawable建议的插入内容以将内容放入drawable的边界内。 正值移向Drawable的中心(设置Rect.inset)。

Parameters
padding Rect
Returns
boolean true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0.

getState

int[] getState ()

描述了当前的状态,如primitve国家的联盟,比如 state_focusedstate_selected等,有些可绘可以根据所选择的状态修改他们的影像。

Returns
int[] An array of resource Ids describing the current state.

getTransparentRegion

Region getTransparentRegion ()

返回表示完全透明的Drawable部分的区域。 这可用于执行绘图操作,确定绘制Drawable时目标的哪些部分不会更改。 默认实现返回null,表示没有透明区域; 如果子类想要提供这个优化信息,子类可以选择性地覆盖它以返回一个实际的区域,但并不要求它们这样做。

Returns
Region Returns null if the Drawables has no transparent region to report, else a Region holding the parts of the Drawable's bounds that are transparent.

inflate

void inflate (Resources res, 
                XmlPullParser parser, 
                AttributeSet attrs, 
                Resources.Theme theme)

从可选的由主题设计的XML资源中扩展此Drawable。 对于每个Drawable,这不能被调用一次以上。 请注意,框架可能已经调用过这一次从XML资源创建Drawable实例。

Parameters
res Resources: Resources used to resolve attribute values
parser XmlPullParser: XML parser from which to inflate this Drawable
attrs AttributeSet: Base set of attribute values
theme Resources.Theme: Theme to apply, may be null
Throws
XmlPullParserException
IOException

inflate

void inflate (Resources res, 
                XmlPullParser parser, 
                AttributeSet attrs)

从XML资源膨胀此Drawable。 不适用主题。

Parameters
res Resources
parser XmlPullParser
attrs AttributeSet
Throws
XmlPullParserException
IOException

isAutoMirrored

boolean isAutoMirrored ()

当它的布局方向是从右到左的RTL时,告诉它是否自动镜像。 LayoutDirection

Returns
boolean boolean Returns true if this Drawable will be automatically mirrored.

isRunning

boolean isRunning ()

指示动画是否正在运行。

Returns
boolean True if the animation is running, false otherwise.

isStateful

boolean isStateful ()

指示此drawable是否会根据状态更改其外观。 客户可以使用它来确定是否有必要计算它们的状态并调用setState。

Returns
boolean True if this drawable changes its appearance based on state, false otherwise.

jumpToCurrentState

void jumpToCurrentState ()

如果此Drawable确实在状态之间转换动画,请求它立即跳转到当前状态并跳过任何活动动画。

mutate

Drawable mutate ()

使这个drawable可变。 这个操作不能逆转。 一个可变的drawable保证不与其他drawable共享它的状态。 当你需要修改从资源加载的drawable的属性时,这是特别有用的。 默认情况下,从同一资源加载的所有可绘制实例共享一个公共状态; 如果修改一个实例的状态,则所有其他实例都将收到相同的修改。 在可变Drawable上调用此方法将不起作用。

Returns
Drawable This drawable.

setAlpha

void setAlpha (int alpha)

为drawable指定一个alpha值。 0表示完全透明,255表示完全不透明。

Parameters
alpha int

setAutoMirrored

void setAutoMirrored (boolean mirrored)

设置当其布局方向为RTL(从右到左)时,此Drawable是否自动镜像。 LayoutDirection

Parameters
mirrored boolean: Set to true if the Drawable should be mirrored, false if not.

setChangingConfigurations

void setChangingConfigurations (int configs)

设置该drawable可能更改的配置参数的掩码,要求重新创建它。

Parameters
configs int: A mask of the changing configuration parameters, as defined by ActivityInfo.

setColorFilter

void setColorFilter (ColorFilter colorFilter)

为绘图指定一个可选的颜色过滤器。

如果Drawable具有ColorFilter,则Drawable的绘图内容的每个输出像素在混合到Canvas的渲染目标之前将被颜色过滤器修改。

通过 null删除任何现有的颜色过滤器。

注意:设置非 null颜色过滤器会禁用 tint

Parameters
colorFilter ColorFilter: The color filter to apply, or null to remove the existing color filter

setColorFilter

void setColorFilter (int color, 
                PorterDuff.Mode mode)

指定一个颜色和Porter-Duff模式作为该drawable的颜色过滤器。

方便 setColorFilter(ColorFilter)构建 PorterDuffColorFilter

注意:设置彩色滤镜禁用 tint

Parameters
color int
mode PorterDuff.Mode

setFilterBitmap

void setFilterBitmap (boolean filter)

设置为true时,在缩放或旋转时使可绘制滤镜具有双线性采样的位图。

当位图旋转时,这可以改善外观。 如果drawable不使用位图,则该调用将被忽略。

Parameters
filter boolean

setHotspot

void setHotspot (float x, 
                float y)

指定可绘制内的热点位置。

Parameters
x float: The X coordinate of the center of the hotspot
y float: The Y coordinate of the center of the hotspot

setHotspotBounds

void setHotspotBounds (int left, 
                int top, 
                int right, 
                int bottom)

设置热点受限的边界,如果它们应该与可绘制边界不同。

Parameters
left int: position in pixels of the left bound
top int: position in pixels of the top bound
right int: position in pixels of the right bound
bottom int: position in pixels of the bottom bound

setState

boolean setState (int[] stateSet)

为drawable指定一组状态。 这些是特定用例,请参阅相关文档。 作为一个例子,像按钮widget的背景理解以下状态:[ state_focusedstate_pressed

如果您提供的新状态导致Drawable的外观发生变化,则它负责调用 invalidateSelf()以重绘本身, 并且将从此函数返回true。

注意:Drawable持有 stateSet的引用,直到给它一个新的状态数组,所以在这段时间内你不能修改这个数组。

Parameters
stateSet int: The new set of states to be displayed.
Returns
boolean Returns true if this change in state has caused the appearance of the Drawable to change (hence requiring an invalidate), otherwise returns false.

setTint

void setTint (int tint)

指定该drawable的色调颜色。

Drawable的绘图内容在绘制到屏幕前将与它的色调混合在一起。 这功能类似于setColorFilter(int, PorterDuff.Mode)

要清除色调, null setTintList(ColorStateList)传递到 setTintList(ColorStateList)

注意:通过 setColorFilter(ColorFilter)setColorFilter(int, PorterDuff.Mode)设置颜色过滤器会覆盖色调。

Parameters
tint int: Color to use for tinting this drawable

setTintList

void setTintList (ColorStateList tint)

指定该drawable的色彩颜色作为颜色状态列表。

Drawable的绘图内容在绘制到屏幕前将与它的色调混合在一起。 这与setColorFilter(int, PorterDuff.Mode)功能类似。

注意:通过 setColorFilter(ColorFilter)setColorFilter(int, PorterDuff.Mode)设置颜色过滤器会覆盖色彩。

Parameters
tint ColorStateList: Color state list to use for tinting this drawable, or null to clear the tint

setTintMode

void setTintMode (PorterDuff.Mode tintMode)

指定该drawable的色调混合模式。

定义在绘制屏幕之前,该绘制的色调应该如何混合到绘图中。 默认色调模式是SRC_IN

注意:通过 setColorFilter(ColorFilter)setColorFilter(int, PorterDuff.Mode)设置颜色过滤器会覆盖色彩。

Parameters
tintMode PorterDuff.Mode: A Porter-Duff blending mode

setVisible

boolean setVisible (boolean visible, 
                boolean restart)

设置此Drawable是否可见。 这通常不会影响Drawable的行为,但它是一些可供Drawables使用的提示,例如,可以决定是否运行动画。

Parameters
visible boolean: Set to true if visible, false if not.
restart boolean: You can supply true here to force the drawable to behave as if it has just become visible, even if it had last been set visible. Used for example to force animations to restart.
Returns
boolean boolean Returns true if the new visibility is different than its previous state.

start

void start ()

开始drawable的动画。

stop

void stop ()

停止绘图的动画。

Protected methods

onBoundsChange

void onBoundsChange (Rect bounds)

如果您根据边界而变化,请在您的子类中覆盖此内容以更改外观。

Parameters
bounds Rect

onLevelChange

boolean onLevelChange (int level)

如果您根据级别而变化,请在您的子类中覆盖此内容以更改外观。

Parameters
level int
Returns
boolean Returns true if the level change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last level.

onStateChange

boolean onStateChange (int[] state)

如果您认识到指定的状态,请在您的子类中覆盖此内容以更改外观。

Parameters
state int
Returns
boolean Returns true if the state change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last state.

Hooray!