Drawable 详解
public abstract class Drawable?
extends?Object?
| java.lang.Object | |
| ???? | android.graphics.drawable.Drawable |
| AdaptiveIconDrawable,?AnimatedImageDrawable,?AnimatedVectorDrawable,?BitmapDrawable,?ColorDrawable,?DrawableContainer,?DrawableWrapper,?GradientDrawable,?LayerDrawable,?NinePatchDrawable,?PictureDrawable,?ShapeDrawable,?VectorDrawable |
| AnimatedStateListDrawable,?AnimationDrawable,?ClipDrawable,?InsetDrawable,?LevelListDrawable,?PaintDrawable,?RippleDrawable,?RotateDrawable,?ScaleDrawable,?StateListDrawable,?TransitionDrawable Drawable是 可以被畫的東西的通用抽象類,多數(shù)情況下Drawable一般用作為畫在屏幕上資源;Drawable類提供了一個(gè)通用的API去處理優(yōu)先的各種類型的可視化資源。與View不同,Drawble 沒有接收事件和用戶交互的能力。 除了簡單的繪畫,Drawable提供了大量的通用機(jī)制給客戶端去和正在被繪制的進(jìn)行交互。
雖然通常在應(yīng)用中不可見,但Drawables 會(huì)以以下幾種形式顯示:
自定義drawables所有版本Android允許Drawable類被擴(kuò)展和用在運(yùn)行時(shí)取代framework提供的drawable。API 24開始,自定義drawables類可以用在XML中。 注意:自定義drawable類只能在你的應(yīng)用包中使用,其他的應(yīng)用是不能取加載它們的。 最低限度,自定義drawable類必須實(shí)現(xiàn)Drawable的abstract方法和重載draw(Canvas)方法去繪制內(nèi)容。 自定義drawbles 類可以在XML中以多種形式使用:用完整的類名作為XML元素的名稱。對(duì)于這個(gè)方法,自定義drawable類必須是public高層級(jí)的類。 |
? ?
<com.myapp.MyCustomDrawable xmlns:android="http://schemas.android.com/apk/res/android"android:color="#ffff0000" />????用drawable作為XML元素名并且從類的屬性指定完整路徑名。這個(gè)方法可以用在public 高層級(jí)類和public static 內(nèi)部類。
?<drawable xmlns:android="http://schemas.android.com/apk/res/android"
?class="com.myapp.MyTopLevelClass$InnerCustomDrawable"
?android:color="#ffff0000" />
總結(jié)
| 接口 | Drawable.Callback 如果想要?jiǎng)?chuàng)建一個(gè)動(dòng)畫繼承?Drawable?的drawable,就實(shí)現(xiàn)這個(gè)接口 |
| 類 | Drawable.ConstantState 這個(gè)抽象類被Drawables用來存儲(chǔ)Drawables之間的共享狀態(tài)和數(shù)據(jù) |
| Drawable() |
| void | applyTheme(Resources.Theme?t) Applies the specified theme to this Drawable and its children. 應(yīng)用指定的theme(主題)在Drawable和它的孩子 |
| boolean | canApplyTheme() |
| void | clearColorFilter() Removes the color filter for this drawable. 從drawable中移除顏色過濾器 |
| final?Rect | copyBounds() Return a copy of the drawable's bounds in a new Rect. 在新的矩形(Rect)返回一個(gè)drawable的約束副本 |
| final void | copyBounds(Rect?bounds) Return a copy of the drawable's bounds in the specified Rect (allocated by the caller). 在指定的矩形(Rect)返回一個(gè)drawable的約束副本 |
| static?Drawable | createFromPath(String?pathName) Create a drawable from file path name. 從路徑名(pathName)創(chuàng)建一個(gè)drawable |
| static?Drawable | createFromResourceStream(Resources?res,?TypedValue?value,?InputStream?is,String?srcName,?BitmapFactory.Options?opts) This method was deprecated in API level P. Prefer the version without an Options object. 這個(gè)方法在API P 中已經(jīng)廢棄了,請(qǐng)使用下面的方法 |
| static?Drawable | createFromResourceStream(Resources?res,?TypedValue?value,?InputStream?is,String?srcName) Create a drawable from an inputstream, using the given resources and value to determine density information. 從輸入流創(chuàng)建一個(gè)drawable,使用給定的資源和值去決定密度信息。 |
| static?Drawable | createFromStream(InputStream?is,?String?srcName) Create a drawable from an inputstream 從輸入流創(chuàng)建一個(gè)drawable |
| static?Drawable | createFromXml(Resources?r,?XmlPullParser?parser) Create a drawable from an XML document. 從一個(gè)XML文件中創(chuàng)建一個(gè)drawable |
| static?Drawable | createFromXml(Resources?r,?XmlPullParser?parser,?Resources.Theme?theme) Create a drawable from an XML document using an optional?Resources.Theme. 從一個(gè)XML文檔用Resources.Theme創(chuàng)建一個(gè)drawable |
| static?Drawable | createFromXmlInner(Resources?r,?XmlPullParser?parser,?AttributeSet?attrs,Resources.Theme?theme) Create a drawable from inside an XML document using an optional?Resources.Theme. 從一個(gè)XML文檔使用一個(gè)可選的Resources.Theme創(chuàng)建一個(gè)drawable |
| static?Drawable | createFromXmlInner(Resources?r,?XmlPullParser?parser,?AttributeSet?attrs) Create from inside an XML document. 從一個(gè)XML文檔內(nèi)創(chuàng)建 |
| abstract void | draw(Canvas?canvas) Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter). 在它的約束內(nèi)繪制,并遵從可選的效果,例如透明度alpha 和顏色過濾器 |
| int | getAlpha() Gets the current alpha value for the drawable. 獲取當(dāng)前透明度的值 |
| final?Rect | getBounds() Return the drawable's bounds Rect. 返回drawable的約束矩形 |
| Drawable.Callback | getCallback() Return the current?Drawable.Callback?implementation attached to this Drawable. 返回當(dāng)前這個(gè)Drawable實(shí)現(xiàn)的Drawable.Callback |
| int | getChangingConfigurations() Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. 返回drawable可能會(huì)改變的配置參數(shù),這需要drawable重建 |
| ColorFilter | getColorFilter() Returns the current color filter, or?null?if none set. 返回當(dāng)前的顏色過濾器,返回null如果沒設(shè)置的話 |
| Drawable.ConstantState | getConstantState() Return a?Drawable.ConstantState?instance that holds the shared state of this Drawable. 返回存有這個(gè)Drawable的共享狀態(tài)的?Drawable.ConstantState?實(shí)例。 |
| Drawable | getCurrent() |
| Rect | getDirtyBounds() Return the drawable's dirty bounds Rect. 返回drawable的臟約束矩形 |
| void | getHotspotBounds(Rect?outRect) Populates?outRect?with the hotspot bounds. 使用熱點(diǎn)約束填充外矩形 |
| int | getIntrinsicHeight() Returns the drawable's intrinsic height. 返回drawable的本身高度 |
| int | getIntrinsicWidth() Returns the drawable's intrinsic width. 返回drawable的本身寬度 |
| int | getLayoutDirection() Returns the resolved layout direction for this Drawable. 返回Drawable的布局方向 |
| final int | getLevel() Retrieve the current level. 查詢當(dāng)前的level |
| int | getMinimumHeight() Returns the minimum height suggested by this Drawable. 返回Drawable的建議最小高度 |
| int | getMinimumWidth() Returns the minimum width suggested by this Drawable. 返回Drawable的建議最小寬度 |
| abstract int | getOpacity() Return the opacity/transparency of this Drawable. 返回Drawable的不透明度或者透明度 |
| void | getOutline(Outline?outline) Called to get the drawable to populate the Outline that defines its drawing area. 調(diào)用此方法去獲取drawable去填充定義在繪畫區(qū)域的輪廓 |
| boolean | getPadding(Rect?padding) Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. 返回內(nèi)容與約束邊框的內(nèi)邊距 |
| int[] | getState() Describes the current state, as a union of primitve states, such as?state_focused,state_selected, etc. 描述當(dāng)前狀態(tài),作為一個(gè)聯(lián)合的基本狀態(tài),例如state_focused,state_selected, 等等 |
| Region | getTransparentRegion() Returns a Region representing the part of the Drawable that is completely transparent. 返回完全透明的范圍 |
| void | inflate(Resources?r,?XmlPullParser?parser,?AttributeSet?attrs,?Resources.Theme?theme) Inflate this Drawable from an XML resource optionally styled by a theme. 從某個(gè)主題樣式的XML資源填充這個(gè)drawable |
| void | inflate(Resources?r,?XmlPullParser?parser,?AttributeSet?attrs) Inflate this Drawable from an XML resource. 從XML 資源填充Drawable |
| void | invalidateSelf() Use the current?Drawable.Callback?implementation to have this Drawable redrawn. 使用當(dāng)前?Drawable.Callback實(shí)現(xiàn)讓這個(gè)Drawable重新繪制。 |
| boolean | isAutoMirrored() Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. 是否自動(dòng)生成鏡像 |
| boolean | isFilterBitmap() |
| boolean | isStateful() Indicates whether this drawable will change its appearance based on state. 標(biāo)識(shí)是否根據(jù)狀態(tài)來改變它的顯示 |
| final boolean | isVisible() |
| void | jumpToCurrentState() If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations. 如果這個(gè)Drawable從狀態(tài)之間執(zhí)行轉(zhuǎn)換動(dòng)畫,詢問他立即調(diào)到當(dāng)前狀態(tài)并且跳過所有的動(dòng)畫。 |
| Drawable | mutate() Make this drawable mutable. 讓這個(gè)Drawable易變的。 |
| boolean | onLayoutDirectionChanged(int layoutDirection) Called when the drawable's resolved layout direction changes. 在drawable的布局方向改變時(shí)調(diào)用。 |
| static int | resolveOpacity(int op1,?int op2) Return the appropriate opacity value for two source opacities. 在兩種不透明源中返回恰當(dāng)?shù)牟煌该鞫戎?/p> |
| void | scheduleSelf(Runnable?what,?long when) Use the current?Drawable.Callback?implementation to have this Drawable scheduled. |
| abstract void | setAlpha(int alpha) Specify an alpha value for the drawable. 定義drawable的透明度 |
| void | setAutoMirrored(boolean mirrored) Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). 設(shè)置自動(dòng)鏡像 |
| void | setBounds(int left,?int top,?int right,?int bottom) Specify a bounding rectangle for the Drawable. 定義Drawable的約束矩形 |
| void | setBounds(Rect?bounds) Specify a bounding rectangle for the Drawable. 定義Drawable的約束矩形 |
| final void | setCallback(Drawable.Callback?cb) Bind a?Drawable.Callback?object to this Drawable. 給Drawable綁定Drawable.Callback對(duì)象? |
| void | setChangingConfigurations(int configs) Set a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. |
| void | setColorFilter(int color,?PorterDuff.Mode?mode) Specify a color and Porter-Duff mode to be the color filter for this drawable. |
| abstract void | setColorFilter(ColorFilter?colorFilter) Specify an optional color filter for the drawable. |
| void | setDither(boolean dither) This method was deprecated in API level 23. This property is ignored. |
| void | setFilterBitmap(boolean filter) Set to true to have the drawable filter its bitmaps with bilinear sampling when they are scaled or rotated. |
| void | setHotspot(float x,?float y) Specifies the hotspot's location within the drawable. |
| void | setHotspotBounds(int left,?int top,?int right,?int bottom) Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds. |
| final boolean | setLayoutDirection(int layoutDirection) Set the layout direction for this drawable. |
| final boolean | setLevel(int level) Specify the level for the drawable. |
| boolean | setState(int[] stateSet) Specify a set of states for the drawable. |
| void | setTint(int tintColor) Specifies tint color for this drawable. |
| void | setTintList(ColorStateList?tint) Specifies tint color for this drawable as a color state list. |
| void | setTintMode(PorterDuff.Mode?tintMode) Specifies a tint blending mode for this drawable. |
| boolean | setVisible(boolean visible,?boolean restart) Set whether this Drawable is visible. |
| void | unscheduleSelf(Runnable?what) Use the current?Drawable.Callback?implementation to have this Drawable unscheduled. |
總結(jié)
以上是生活随笔為你收集整理的Drawable 详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 内存分配——Thinking
- 下一篇: Animatable API介绍