public class ShapeDrawable
extends android.graphics.drawable.Drawable
GradientDrawable 的基础上改造| Constructor and Description |
|---|
ShapeDrawable() |
ShapeDrawable(ShapeState state) |
| Modifier and Type | Method and Description |
|---|---|
void |
draw(android.graphics.Canvas canvas) |
int |
getAlpha() |
int |
getChangingConfigurations() |
android.graphics.drawable.Drawable.ConstantState |
getConstantState() |
int |
getIntrinsicHeight() |
int |
getIntrinsicWidth() |
int |
getOpacity() |
boolean |
getPadding(android.graphics.Rect padding) |
ShapeState |
getShapeState()
获取 Shape 状态对象
|
void |
intoBackground(android.view.View view)
将当前 Drawable 应用到 View 背景
|
android.graphics.drawable.Drawable |
mutate() |
protected void |
onBoundsChange(android.graphics.Rect r) |
protected boolean |
onLevelChange(int level) |
void |
setAlpha(int alpha) |
void |
setColorFilter(android.graphics.ColorFilter cf) |
ShapeDrawable |
setDashGap(float dashGap)
设置虚线间隔(虚线与虚线之间的间隔)
|
ShapeDrawable |
setDashWidth(float dashWidth)
设置边框虚线宽度(为 0 就是实线,大于 0 就是虚线)
|
void |
setDither(boolean dither) |
ShapeDrawable |
setGradientAngle(int angle)
设置渐变角度
|
ShapeDrawable |
setGradientCenter(float x,
float y)
设置渐变中心位置
|
ShapeDrawable |
setGradientColors(int[] colors)
设置渐变颜色
|
ShapeDrawable |
setGradientOrientation(ShapeGradientOrientation orientation)
设置渐变方向
|
ShapeDrawable |
setGradientRadius(float radius)
设置渐变半径大小
|
ShapeDrawable |
setGradientType(int type)
设置 Shape 渐变类型
|
ShapeDrawable |
setInnerRadius(int radius)
设置内环的半径
|
ShapeDrawable |
setInnerRadiusRatio(float radiusRatio)
设置内环的半径比率
|
ShapeDrawable |
setPadding(android.graphics.Rect padding) |
ShapeDrawable |
setRadius(float radius)
指定渐变角的半径。 如果这 > 0,则可绘制对象将绘制在圆角矩形中,而不是矩形中。 仅当形状为RECTANGLE类型时才使用此属性。
注意:更改此属性将影响从资源加载的可绘制对象的所有实例。 建议在更改此属性之前调用mutate() 。
|
ShapeDrawable |
setRadius(float topLeftRadius,
float topRightRadius,
float bottomLeftRadius,
float bottomRightRadius) |
ShapeDrawable |
setShadowColor(int color)
设置阴影颜色
|
ShapeDrawable |
setShadowOffsetX(int offsetX)
设置阴影水平偏移
|
ShapeDrawable |
setShadowOffsetY(int offsetY)
阴影垂直偏移
|
ShapeDrawable |
setShadowSize(int size)
设置阴影大小
|
ShapeDrawable |
setShape(int shape)
设置 Shape 形状
|
ShapeDrawable |
setSize(int width,
int height)
设置 Shape 大小
|
ShapeDrawable |
setSolidColor(int color)
设置填充颜色
|
ShapeDrawable |
setStroke(int width,
int color,
float dashWidth,
float dashGap)
初始化边框属性
|
ShapeDrawable |
setStrokeColor(int color)
设置边框颜色
|
ShapeDrawable |
setStrokeWidth(int width)
设置边框宽度
|
ShapeDrawable |
setThickness(int size)
设置外环的厚度
|
ShapeDrawable |
setThicknessRatio(float radiusRatio)
设置外环的厚度比率
|
ShapeDrawable |
setUseLevel(boolean useLevel)
Sets whether or not this drawable will honor its
level
property. |
applyTheme, canApplyTheme, clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getColorFilter, getCurrent, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getOutline, getState, getTransparentRegion, inflate, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isStateful, isVisible, jumpToCurrentState, onLayoutDirectionChanged, onStateChange, resolveOpacity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setFilterBitmap, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintList, setTintMode, setVisible, unscheduleSelfpublic ShapeDrawable()
public ShapeDrawable(ShapeState state)
public ShapeState getShapeState()
public boolean getPadding(android.graphics.Rect padding)
getPadding in class android.graphics.drawable.Drawablepublic ShapeDrawable setPadding(android.graphics.Rect padding)
public ShapeDrawable setShape(int shape)
shape - Shape 形状类型public ShapeDrawable setSize(int width, int height)
width - Shape 宽度height - Shape 高度public ShapeDrawable setRadius(float radius)
radius - 矩形角的半径(以像素为单位)public ShapeDrawable setRadius(float topLeftRadius, float topRightRadius, float bottomLeftRadius, float bottomRightRadius)
public ShapeDrawable setSolidColor(int color)
public ShapeDrawable setStrokeColor(int color)
public ShapeDrawable setStrokeWidth(int width)
public ShapeDrawable setDashWidth(float dashWidth)
public ShapeDrawable setDashGap(float dashGap)
public ShapeDrawable setStroke(int width, int color, float dashWidth, float dashGap)
public ShapeDrawable setGradientColors(int[] colors)
public ShapeDrawable setGradientType(int type)
public ShapeDrawable setGradientCenter(float x, float y)
public ShapeDrawable setGradientRadius(float radius)
public ShapeDrawable setUseLevel(boolean useLevel)
Sets whether or not this drawable will honor its level
property.
Note: changing this property will affect all instances
of a drawable loaded from a resource. It is recommended to invoke
mutate() before changing this property.
useLevel - True if this drawable should honor its level, false otherwisemutate(),
Drawable.setLevel(int),
Drawable.getLevel()public ShapeDrawable setGradientAngle(int angle)
public ShapeDrawable setGradientOrientation(ShapeGradientOrientation orientation)
public ShapeDrawable setInnerRadius(int radius)
public ShapeDrawable setInnerRadiusRatio(float radiusRatio)
public ShapeDrawable setThickness(int size)
public ShapeDrawable setThicknessRatio(float radiusRatio)
public ShapeDrawable setShadowColor(int color)
public ShapeDrawable setShadowSize(int size)
public ShapeDrawable setShadowOffsetX(int offsetX)
public ShapeDrawable setShadowOffsetY(int offsetY)
public void intoBackground(android.view.View view)
public void draw(android.graphics.Canvas canvas)
draw in class android.graphics.drawable.Drawablepublic int getChangingConfigurations()
getChangingConfigurations in class android.graphics.drawable.Drawablepublic void setAlpha(int alpha)
setAlpha in class android.graphics.drawable.Drawablepublic int getAlpha()
getAlpha in class android.graphics.drawable.Drawablepublic void setDither(boolean dither)
setDither in class android.graphics.drawable.Drawablepublic void setColorFilter(android.graphics.ColorFilter cf)
setColorFilter in class android.graphics.drawable.Drawablepublic int getOpacity()
getOpacity in class android.graphics.drawable.Drawableprotected void onBoundsChange(android.graphics.Rect r)
onBoundsChange in class android.graphics.drawable.Drawableprotected boolean onLevelChange(int level)
onLevelChange in class android.graphics.drawable.Drawablepublic int getIntrinsicWidth()
getIntrinsicWidth in class android.graphics.drawable.Drawablepublic int getIntrinsicHeight()
getIntrinsicHeight in class android.graphics.drawable.Drawablepublic android.graphics.drawable.Drawable.ConstantState getConstantState()
getConstantState in class android.graphics.drawable.Drawablepublic android.graphics.drawable.Drawable mutate()
mutate in class android.graphics.drawable.Drawable