public class LayerDrawable extends LollipopDrawable implements android.graphics.drawable.Drawable.Callback
<layer-list>
element.
Each Drawable in the layer is defined in a nested <item>
.
For more information, see the guide to
Drawable Resources.Modifier and Type | Field and Description |
---|---|
static int |
PADDING_MODE_NEST
Padding mode used to nest each layer inside the padding of the previous
layer.
|
static int |
PADDING_MODE_STACK
Padding mode used to stack each layer directly atop the previous layer.
|
Constructor and Description |
---|
LayerDrawable(android.graphics.drawable.Drawable[] layers)
Creates a new layer drawable with the list of specified layers.
|
Modifier and Type | Method and Description |
---|---|
int |
addLayer(android.graphics.drawable.Drawable dr)
Adds a new layer containing the specified
drawable to the end of
the layer list and returns its index. |
void |
applyTheme(android.content.res.Resources.Theme t)
Applies the specified theme to this Drawable and its children.
|
boolean |
canApplyTheme() |
void |
draw(android.graphics.Canvas canvas) |
android.graphics.drawable.Drawable |
findDrawableByLayerId(int id)
Looks for a layer with the given ID and returns its
Drawable . |
int |
findIndexByLayerId(int id)
Returns the layer with the specified
id . |
int |
getAlpha()
Gets the current alpha value for the drawable. 0 means fully transparent,
255 means fully opaque.
|
int |
getBottomPadding()
Returns the bottom padding in pixels.
|
int |
getChangingConfigurations() |
android.graphics.drawable.Drawable.ConstantState |
getConstantState() |
android.graphics.drawable.Drawable |
getDrawable(int index)
Returns the drawable for the layer at the specified index.
|
int |
getEndPadding()
Returns the end padding in pixels.
|
void |
getHotspotBounds(android.graphics.Rect outRect) |
int |
getId(int index)
Returns the ID of the specified layer.
|
int |
getIntrinsicHeight() |
int |
getIntrinsicWidth() |
int |
getLayerGravity(int index) |
int |
getLayerHeight(int index) |
int |
getLayerInsetBottom(int index) |
int |
getLayerInsetEnd(int index) |
int |
getLayerInsetLeft(int index) |
int |
getLayerInsetRight(int index) |
int |
getLayerInsetStart(int index) |
int |
getLayerInsetTop(int index) |
int |
getLayerWidth(int index) |
int |
getLeftPadding()
Returns the left padding in pixels.
|
int |
getNumberOfLayers()
Returns the number of layers contained within this layer drawable.
|
int |
getOpacity() |
void |
getOutline(android.graphics.Outline outline)
Populates
outline with the first available (non-empty) layer outline. |
boolean |
getPadding(android.graphics.Rect padding) |
int |
getPaddingMode() |
int |
getRightPadding()
Returns the right padding in pixels.
|
int |
getStartPadding()
Returns the start padding in pixels.
|
int |
getTopPadding()
Returns the top padding in pixels.
|
void |
inflate(android.content.res.Resources r,
org.xmlpull.v1.XmlPullParser parser,
android.util.AttributeSet attrs,
android.content.res.Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme.
|
void |
invalidateDrawable(android.graphics.drawable.Drawable who) |
boolean |
isAutoMirrored() |
boolean |
isStateful() |
android.graphics.drawable.Drawable |
mutate() |
protected void |
onBoundsChange(android.graphics.Rect bounds) |
boolean |
onLayoutDirectionChanged(int layoutDirection) |
protected boolean |
onLevelChange(int level) |
protected boolean |
onStateChange(int[] state) |
void |
scheduleDrawable(android.graphics.drawable.Drawable who,
java.lang.Runnable what,
long when) |
void |
setAlpha(int alpha) |
void |
setAutoMirrored(boolean mirrored) |
void |
setColorFilter(android.graphics.ColorFilter colorFilter) |
void |
setDither(boolean dither) |
void |
setDrawable(int index,
android.graphics.drawable.Drawable drawable)
Sets the drawable for the layer at the specified index.
|
boolean |
setDrawableByLayerId(int id,
android.graphics.drawable.Drawable drawable)
Replaces the
Drawable for the layer with the given id. |
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.
|
void |
setId(int index,
int id)
Sets the ID of a layer.
|
void |
setLayerGravity(int index,
int gravity)
Sets the gravity used to position or stretch the specified layer within
its container.
|
void |
setLayerHeight(int index,
int h) |
void |
setLayerInset(int index,
int l,
int t,
int r,
int b)
Specifies the insets in pixels for the drawable at the specified index.
|
void |
setLayerInsetBottom(int index,
int b) |
void |
setLayerInsetEnd(int index,
int e) |
void |
setLayerInsetLeft(int index,
int l) |
void |
setLayerInsetRelative(int index,
int s,
int t,
int e,
int b)
Specifies the relative insets in pixels for the drawable at the
specified index.
|
void |
setLayerInsetRight(int index,
int r) |
void |
setLayerInsetStart(int index,
int s) |
void |
setLayerInsetTop(int index,
int t) |
void |
setLayerSize(int index,
int w,
int h)
Sets an explicit size for the specified layer.
|
void |
setLayerWidth(int index,
int w) |
void |
setOpacity(int opacity)
Sets the opacity of this drawable directly instead of collecting the
states from the layers.
|
void |
setPadding(int left,
int top,
int right,
int bottom)
Sets the absolute padding.
|
void |
setPaddingMode(int mode)
Specifies how layer padding should affect the bounds of subsequent
layers.
|
void |
setPaddingRelative(int start,
int top,
int end,
int bottom)
Sets the relative padding.
|
void |
setTintList(android.content.res.ColorStateList tint)
Specifies a tint for this drawable as a color state list.
|
void |
setTintMode(android.graphics.PorterDuff.Mode tintMode)
Specifies a tint blending mode for this drawable.
|
boolean |
setVisible(boolean visible,
boolean restart) |
void |
unscheduleDrawable(android.graphics.drawable.Drawable who,
java.lang.Runnable what) |
getColorFilter, setTint
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getCurrent, getDirtyBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getState, getTransparentRegion, inflate, invalidateSelf, isFilterBitmap, isVisible, jumpToCurrentState, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setFilterBitmap, setLayoutDirection, setLevel, setState, unscheduleSelf
public static final int PADDING_MODE_NEST
setPaddingMode(int)
,
Constant Field Valuespublic static final int PADDING_MODE_STACK
setPaddingMode(int)
,
Constant Field Valuespublic LayerDrawable(@NonNull android.graphics.drawable.Drawable[] layers)
layers
- a list of drawables to use as layers in this new drawable, must be non-nullpublic void inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
LollipopDrawable
inflate
in class LollipopDrawable
r
- Resources used to resolve attribute valuesparser
- XML parser from which to inflate this Drawableattrs
- Base set of attribute valuestheme
- Theme to apply, may be nullorg.xmlpull.v1.XmlPullParserException
java.io.IOException
public void applyTheme(android.content.res.Resources.Theme t)
LollipopDrawable
applyTheme
in class LollipopDrawable
public boolean canApplyTheme()
canApplyTheme
in class LollipopDrawable
public int addLayer(android.graphics.drawable.Drawable dr)
drawable
to the end of
the layer list and returns its index.dr
- The drawable to add as a new layer.public android.graphics.drawable.Drawable findDrawableByLayerId(int id)
Drawable
.
If multiple layers are found for the given ID, returns the
Drawable
for the matching layer at the highest index.id
- The layer ID to search for.Drawable
for the highest-indexed layer that has the given ID, or null if
not found.public void setId(int index, int id)
index
- The index of the layer to modify, must be in the range 0...getNumberOfLayers()-1
.id
- The id to assign to the layer.getId(int)
public int getId(int index)
index
- The index of the layer, must be in the range 0...getNumberOfLayers()-1
.View.NO_ID
if the layer has no id.setId(int, int)
public int getNumberOfLayers()
public boolean setDrawableByLayerId(int id, android.graphics.drawable.Drawable drawable)
Drawable
for the layer with the given id.id
- The layer ID to search for.drawable
- The replacement Drawable
.Drawable
was replaced (could return false if the id was not
found).public int findIndexByLayerId(int id)
id
.
If multiple layers have the same ID, returns the layer with the lowest
index.id
- The ID of the layer to return.public void setDrawable(int index, android.graphics.drawable.Drawable drawable)
index
- The index of the layer to modify, must be in the range 0...getNumberOfLayers()-1
.drawable
- The drawable to set for the layer.getDrawable(int)
public android.graphics.drawable.Drawable getDrawable(int index)
index
- The index of the layer, must be in the range 0...getNumberOfLayers()-1
.Drawable
at the specified layer index.setDrawable(int, Drawable)
public void setLayerSize(int index, int w, int h)
setLayerGravity(int, int)
for more information.index
- the index of the layer to adjustw
- width in pixels, or -1 to use the intrinsic widthh
- height in pixels, or -1 to use the intrinsic heightgetLayerWidth(int)
,
getLayerHeight(int)
public void setLayerWidth(int index, int w)
index
- the index of the layer to adjustw
- width in pixels, or -1 to use the intrinsic widthpublic int getLayerWidth(int index)
index
- the index of the drawable to adjustsetLayerSize(int, int, int)
public void setLayerHeight(int index, int h)
index
- the index of the layer to adjusth
- height in pixels, or -1 to use the intrinsic heightpublic int getLayerHeight(int index)
index
- the index of the drawable to adjustsetLayerSize(int, int, int)
public void setLayerGravity(int index, int gravity)
setLayerInset(int, int, int, int, int)
) or padding (see
setPaddingMode(int)
).
If gravity is specified as Gravity.NO_GRAVITY
, the default
behavior depends on whether an explicit width or height has been set
(see setLayerSize(int, int, int)
), If a dimension is not set,
gravity in that direction defaults to Gravity.FILL_HORIZONTAL
or
Gravity.FILL_VERTICAL
; otherwise, gravity in that direction
defaults to Gravity.LEFT
or Gravity.TOP
.index
- the index of the drawable to adjustgravity
- the gravity to set for the layergetLayerGravity(int)
public int getLayerGravity(int index)
index
- the index of the layersetLayerGravity(int, int)
public void setLayerInset(int index, int l, int t, int r, int b)
index
- the index of the drawable to adjustl
- number of pixels to add to the left boundt
- number of pixels to add to the top boundr
- number of pixels to subtract from the right boundb
- number of pixels to subtract from the bottom boundpublic void setLayerInsetRelative(int index, int s, int t, int e, int b)
index
- the index of the layer to adjusts
- number of pixels to inset from the start boundt
- number of pixels to inset from the top bounde
- number of pixels to inset from the end boundb
- number of pixels to inset from the bottom boundpublic void setLayerInsetLeft(int index, int l)
index
- the index of the layer to adjustl
- number of pixels to inset from the left boundpublic int getLayerInsetLeft(int index)
index
- the index of the layerpublic void setLayerInsetRight(int index, int r)
index
- the index of the layer to adjustr
- number of pixels to inset from the right boundpublic int getLayerInsetRight(int index)
index
- the index of the layerpublic void setLayerInsetTop(int index, int t)
index
- the index of the layer to adjustt
- number of pixels to inset from the top boundpublic int getLayerInsetTop(int index)
index
- the index of the layerpublic void setLayerInsetBottom(int index, int b)
index
- the index of the layer to adjustb
- number of pixels to inset from the bottom boundpublic int getLayerInsetBottom(int index)
index
- the index of the layerpublic void setLayerInsetStart(int index, int s)
index
- the index of the layer to adjusts
- number of pixels to inset from the start boundpublic int getLayerInsetStart(int index)
index
- the index of the layerpublic void setLayerInsetEnd(int index, int e)
index
- the index of the layer to adjuste
- number of pixels to inset from the end boundpublic int getLayerInsetEnd(int index)
index
- the index of the layerpublic void setPaddingMode(int mode)
PADDING_MODE_NEST
.mode
- padding mode, one of: PADDING_MODE_NEST
to nest each layer
inside the padding of the previous layer PADDING_MODE_STACK
to stack
each layer directly atop the previous layer getPaddingMode()
public int getPaddingMode()
setPaddingMode(int)
public void invalidateDrawable(android.graphics.drawable.Drawable who)
invalidateDrawable
in interface android.graphics.drawable.Drawable.Callback
public void scheduleDrawable(android.graphics.drawable.Drawable who, java.lang.Runnable what, long when)
scheduleDrawable
in interface android.graphics.drawable.Drawable.Callback
public void unscheduleDrawable(android.graphics.drawable.Drawable who, java.lang.Runnable what)
unscheduleDrawable
in interface android.graphics.drawable.Drawable.Callback
public void draw(android.graphics.Canvas canvas)
draw
in class android.graphics.drawable.Drawable
public int getChangingConfigurations()
getChangingConfigurations
in class android.graphics.drawable.Drawable
public boolean getPadding(android.graphics.Rect padding)
getPadding
in class android.graphics.drawable.Drawable
public void setPadding(int left, int top, int right, int bottom)
-1
, the resolved
padding will use the value computed according to the padding mode (see
setPaddingMode(int)
).
Calling this method clears any relative padding values previously set
using setPaddingRelative(int, int, int, int)
.left
- the left padding in pixels, or -1 to use computed paddingtop
- the top padding in pixels, or -1 to use computed paddingright
- the right padding in pixels, or -1 to use computed paddingbottom
- the bottom padding in pixels, or -1 to use computed paddingsetPaddingRelative(int, int, int, int)
public void setPaddingRelative(int start, int top, int end, int bottom)
-1
, the resolved
padding will use the value computed according to the padding mode (see
setPaddingMode(int)
).
Calling this method clears any absolute padding values previously set
using setPadding(int, int, int, int)
.start
- the start padding in pixels, or -1 to use computed paddingtop
- the top padding in pixels, or -1 to use computed paddingend
- the end padding in pixels, or -1 to use computed paddingbottom
- the bottom padding in pixels, or -1 to use computed paddingsetPadding(int, int, int, int)
public int getLeftPadding()
-1
means there is no explicit padding set for
this dimension. As a result, the value for this dimension returned by
getPadding(Rect)
will be computed from the child layers
according to the padding mode (see getPaddingMode()
.setPadding(int, int, int, int)
,
getPadding(Rect)
public int getRightPadding()
-1
means there is no explicit padding set for
this dimension. As a result, the value for this dimension returned by
getPadding(Rect)
will be computed from the child layers
according to the padding mode (see getPaddingMode()
.setPadding(int, int, int, int)
,
getPadding(Rect)
public int getStartPadding()
-1
means there is no explicit padding set for
this dimension. As a result, the value for this dimension returned by
getPadding(Rect)
will be computed from the child layers
according to the padding mode (see getPaddingMode()
.setPaddingRelative(int, int, int, int)
,
getPadding(Rect)
public int getEndPadding()
-1
means there is no explicit padding set for
this dimension. As a result, the value for this dimension returned by
getPadding(Rect)
will be computed from the child layers
according to the padding mode (see getPaddingMode()
.setPaddingRelative(int, int, int, int)
,
getPadding(Rect)
public int getTopPadding()
-1
means there is no explicit padding set for
this dimension. As a result, the value for this dimension returned by
getPadding(Rect)
will be computed from the child layers
according to the padding mode (see getPaddingMode()
.setPadding(int, int, int, int)
,
setPaddingRelative(int, int, int, int)
,
getPadding(Rect)
public int getBottomPadding()
-1
means there is no explicit padding set for
this dimension. As a result, the value for this dimension returned by
getPadding(Rect)
will be computed from the child layers
according to the padding mode (see getPaddingMode()
.setPadding(int, int, int, int)
,
setPaddingRelative(int, int, int, int)
,
getPadding(Rect)
public void getOutline(@NonNull android.graphics.Outline outline)
outline
with the first available (non-empty) layer outline.getOutline
in class android.graphics.drawable.Drawable
outline
- Outline in which to place the first available layer outlinepublic void setHotspot(float x, float y)
LollipopDrawable
setHotspot
in class LollipopDrawable
x
- The X coordinate of the center of the hotspoty
- The Y coordinate of the center of the hotspotpublic void setHotspotBounds(int left, int top, int right, int bottom)
LollipopDrawable
setHotspotBounds
in class LollipopDrawable
public void getHotspotBounds(android.graphics.Rect outRect)
getHotspotBounds
in class LollipopDrawable
public boolean setVisible(boolean visible, boolean restart)
setVisible
in class android.graphics.drawable.Drawable
public void setDither(boolean dither)
setDither
in class android.graphics.drawable.Drawable
public void setAlpha(int alpha)
setAlpha
in class LollipopDrawable
public int getAlpha()
LollipopDrawable
getAlpha
in class LollipopDrawable
public void setColorFilter(android.graphics.ColorFilter colorFilter)
setColorFilter
in class LollipopDrawable
public void setTintList(android.content.res.ColorStateList tint)
LollipopDrawable
LollipopDrawable.setColorFilter(ColorFilter)
overrides
tint.setTintList
in class LollipopDrawable
tint
- Color state list to use for tinting this drawable, or null to clear the tintLollipopDrawable.setTintMode(PorterDuff.Mode)
public void setTintMode(android.graphics.PorterDuff.Mode tintMode)
LollipopDrawable
LollipopDrawable.setColorFilter(ColorFilter)
overrides
tint.setTintMode
in class LollipopDrawable
tintMode
- Color state list to use for tinting this drawable, or null to clear the tintpublic void setOpacity(int opacity)
opacity
- The opacity to use, or PixelFormat.UNKNOWN
for the
default behaviorPixelFormat.UNKNOWN
,
PixelFormat.TRANSLUCENT
,
PixelFormat.TRANSPARENT
,
PixelFormat.OPAQUE
public int getOpacity()
getOpacity
in class android.graphics.drawable.Drawable
public void setAutoMirrored(boolean mirrored)
setAutoMirrored
in class android.graphics.drawable.Drawable
public boolean isAutoMirrored()
isAutoMirrored
in class android.graphics.drawable.Drawable
public boolean isStateful()
isStateful
in class android.graphics.drawable.Drawable
protected boolean onStateChange(int[] state)
onStateChange
in class android.graphics.drawable.Drawable
protected boolean onLevelChange(int level)
onLevelChange
in class android.graphics.drawable.Drawable
protected void onBoundsChange(android.graphics.Rect bounds)
onBoundsChange
in class android.graphics.drawable.Drawable
public int getIntrinsicWidth()
getIntrinsicWidth
in class android.graphics.drawable.Drawable
public int getIntrinsicHeight()
getIntrinsicHeight
in class android.graphics.drawable.Drawable
public android.graphics.drawable.Drawable.ConstantState getConstantState()
getConstantState
in class android.graphics.drawable.Drawable
public android.graphics.drawable.Drawable mutate()
mutate
in class android.graphics.drawable.Drawable
public boolean onLayoutDirectionChanged(int layoutDirection)
onLayoutDirectionChanged
in class android.graphics.drawable.Drawable