public class ScaleDrawable extends DrawableWrapper
The default level may be specified from XML using the
android:level
property. When
this property is not specified, the default level is 0, which corresponds to
zero height and/or width depending on the values specified for
android.R.styleable#ScaleDrawable_scaleWidth scaleWidth
and
android.R.styleable#ScaleDrawable_scaleHeight scaleHeight
. At run
time, the level may be set via Drawable.setLevel(int)
.
A scale drawable may be defined in an XML file with the <scale>
element. For more information, see the guide to
Drawable
Resources.
Drawable.Callback, Drawable.ConstantState
Constructor and Description |
---|
ScaleDrawable(Drawable drawable,
int gravity,
float scaleWidth,
float scaleHeight)
Creates a new scale drawable with the specified gravity and scale
properties.
|
Modifier and Type | Method and Description |
---|---|
void |
applyTheme(Resources.Theme t)
Applies the specified theme to this Drawable and its children.
|
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).
|
int |
getOpacity()
Return the opacity/transparency of this Drawable.
|
void |
inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs,
Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme.
|
protected void |
onBoundsChange(Rect bounds)
Override this in your subclass to change appearance if you vary based on
the bounds.
|
protected boolean |
onLevelChange(int level)
Override this in your subclass to change appearance if you vary based
on level.
|
canApplyTheme, clearMutated, getAlpha, getChangingConfigurations, getConstantState, getDrawable, getHotspotBounds, getIntrinsicHeight, getIntrinsicWidth, getOpticalInsets, getOutline, getPadding, invalidateDrawable, isStateful, mutate, onLayoutDirectionChanged, onStateChange, scheduleDrawable, setAlpha, setColorFilter, setDrawable, setHotspot, setHotspotBounds, setTintList, setTintMode, setVisible, unscheduleDrawable
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getColorFilter, getCurrent, getDirtyBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getState, getTransparentRegion, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isProjected, isVisible, jumpToCurrentState, obtainAttributes, parseTintMode, resolveOpacity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setDither, setFilterBitmap, setLayoutDirection, setLevel, setState, setTint, setXfermode, unscheduleSelf
public ScaleDrawable(Drawable drawable, int gravity, float scaleWidth, float scaleHeight)
drawable
- the drawable to scalegravity
- gravity constant (see Gravity
used to position
the scaled drawable within the parent containerscaleWidth
- width scaling factor [0...1] to use then the level is
at the maximum value, or -1 to not scale widthscaleHeight
- height scaling factor [0...1] to use then the level
is at the maximum value, or -1 to not scale heightpublic void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme) throws XmlPullParserException, IOException
Drawable
inflate
in class DrawableWrapper
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 nullXmlPullParserException
IOException
public void applyTheme(Resources.Theme t)
Drawable
applyTheme
in class DrawableWrapper
t
- the theme to applypublic void draw(Canvas canvas)
Drawable
draw
in class DrawableWrapper
canvas
- The canvas to draw intopublic int getOpacity()
Drawable
PixelFormat
:
PixelFormat.UNKNOWN
,
PixelFormat.TRANSLUCENT
,
PixelFormat.TRANSPARENT
, or
PixelFormat.OPAQUE
.
An OPAQUE drawable is one that draws all all content within its bounds, completely covering anything behind the drawable. A TRANSPARENT drawable is one that draws nothing within its bounds, allowing everything behind it to show through. A TRANSLUCENT drawable is a drawable in any other state, where the drawable will draw some, but not all, of the content within its bounds and at least some content behind the drawable will be visible. If the visibility of the drawable's contents cannot be determined, the safest/best return value is TRANSLUCENT.
Generally a Drawable should be as conservative as possible with the
value it returns. For example, if it contains multiple child drawables
and only shows one of them at a time, if only one of the children is
TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be
returned. You can use the method Drawable.resolveOpacity(int, int)
to perform a
standard reduction of two opacities to the appropriate single output.
Note that the returned value does not necessarily take into account a
custom alpha or color filter that has been applied by the client through
the Drawable.setAlpha(int)
or Drawable.setColorFilter(android.graphics.ColorFilter)
methods. Some subclasses,
such as BitmapDrawable
, ColorDrawable
, and GradientDrawable
,
do account for the value of Drawable.setAlpha(int)
, but the general behavior is dependent
upon the implementation of the subclass.
getOpacity
in class DrawableWrapper
PixelFormat
protected boolean onLevelChange(int level)
Drawable
onLevelChange
in class DrawableWrapper
protected void onBoundsChange(Rect bounds)
Drawable
onBoundsChange
in class DrawableWrapper