public abstract class RoundedBitmapDrawable extends Drawable
Bitmap
object.
Also see the Bitmap
class, which handles the management and
transformation of raw bitmap graphics, and should be used when drawing to a
Canvas
.
Drawable.Callback, Drawable.ConstantState
Modifier and Type | Method and Description |
---|---|
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 |
getAlpha()
Gets the current alpha value for the drawable. 0 means fully transparent,
255 means fully opaque.
|
Bitmap |
getBitmap()
Returns the bitmap used by this drawable to render.
|
ColorFilter |
getColorFilter()
Returns the current color filter, or
null if none set. |
float |
getCornerRadius() |
int |
getGravity()
Get the gravity used to position/stretch the bitmap within its bounds.
|
int |
getIntrinsicHeight()
Returns the drawable's intrinsic height.
|
int |
getIntrinsicWidth()
Returns the drawable's intrinsic width.
|
int |
getOpacity()
Return the opacity/transparency of this Drawable.
|
Paint |
getPaint()
Returns the paint used to render this drawable.
|
boolean |
hasAntiAlias()
Indicates whether anti-aliasing is enabled for this drawable.
|
boolean |
hasMipMap()
Indicates whether the mipmap hint is enabled on this drawable's bitmap.
|
boolean |
isCircular() |
protected void |
onBoundsChange(Rect bounds)
Override this in your subclass to change appearance if you vary based on
the bounds.
|
void |
setAlpha(int alpha)
Specify an alpha value for the drawable. 0 means fully transparent, and
255 means fully opaque.
|
void |
setAntiAlias(boolean aa)
Enables or disables anti-aliasing for this drawable.
|
void |
setCircular(boolean circular)
Sets the image shape to circular.
|
void |
setColorFilter(ColorFilter cf)
Specify an optional color filter for the drawable.
|
void |
setCornerRadius(float cornerRadius)
Sets the corner radius to be applied when drawing the bitmap.
|
void |
setDither(boolean dither)
Set to true to have the drawable dither its colors when drawn to a
device with fewer than 8-bits per color component.
|
void |
setFilterBitmap(boolean filter)
Set to true to have the drawable filter its bitmaps with bilinear
sampling when they are scaled or rotated.
|
void |
setGravity(int gravity)
Set the gravity used to position/stretch the bitmap within its bounds.
|
void |
setMipMap(boolean mipMap)
Enables or disables the mipmap hint for this drawable's bitmap.
|
void |
setTargetDensity(Canvas canvas)
Set the density scale at which this drawable will be rendered.
|
void |
setTargetDensity(DisplayMetrics metrics)
Set the density scale at which this drawable will be rendered.
|
void |
setTargetDensity(int density)
Set the density at which this drawable will be rendered.
|
applyTheme, canApplyTheme, clearColorFilter, clearMutated, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getChangingConfigurations, getConstantState, getCurrent, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getOpticalInsets, getOutline, getPadding, getState, getTransparentRegion, inflate, inflate, invalidateSelf, isAutoMirrored, isFilterBitmap, isProjected, isStateful, isVisible, jumpToCurrentState, mutate, obtainAttributes, onLayoutDirectionChanged, onLevelChange, onStateChange, parseTintMode, resolveOpacity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setTintList, setTintMode, setVisible, setXfermode, unscheduleSelf
public final Paint getPaint()
public final Bitmap getBitmap()
public void setTargetDensity(Canvas canvas)
canvas
- The Canvas from which the density scale must be obtained.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public void setTargetDensity(DisplayMetrics metrics)
metrics
- The DisplayMetrics indicating the density scale for this drawable.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public void setTargetDensity(int density)
density
- The density scale for this drawable.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public int getGravity()
Gravity
public void setGravity(int gravity)
gravity
- the gravityGravity
public void setMipMap(boolean mipMap)
Bitmap.setHasMipMap(boolean)
for more information.
If the bitmap is null, or the current API version does not support setting a mipmap hint,
calling this method has no effect.mipMap
- True if the bitmap should use mipmaps, false otherwise.hasMipMap()
public boolean hasMipMap()
setMipMap(boolean)
public void setAntiAlias(boolean aa)
aa
- True if the bitmap should be anti-aliased, false otherwise.hasAntiAlias()
public boolean hasAntiAlias()
setAntiAlias(boolean)
public void setFilterBitmap(boolean filter)
Drawable
This can improve appearance when bitmaps are rotated. If the drawable does not use bitmaps, this call is ignored.
setFilterBitmap
in class Drawable
Drawable.isFilterBitmap()
,
Paint.setFilterBitmap(boolean);
public void setDither(boolean dither)
Drawable
setDither
in class Drawable
Paint.setDither(boolean);
public void draw(Canvas canvas)
Drawable
public void setAlpha(int alpha)
Drawable
public int getAlpha()
Drawable
public void setColorFilter(ColorFilter cf)
Drawable
If a Drawable has a ColorFilter, each output pixel of the Drawable's drawing contents will be modified by the color filter before it is blended onto the render target of a Canvas.
Pass null
to remove any existing color filter.
Note: Setting a non-null
color
filter disables tint
.
setColorFilter
in class Drawable
cf
- The color filter to apply, or null
to remove the
existing color filterpublic ColorFilter getColorFilter()
Drawable
null
if none set.getColorFilter
in class Drawable
null
if none setpublic void setCircular(boolean circular)
This overwrites any calls made to setCornerRadius(float)
so far.
public boolean isCircular()
true
if the image is circular, else false
.public void setCornerRadius(float cornerRadius)
protected void onBoundsChange(Rect bounds)
Drawable
onBoundsChange
in class Drawable
public float getCornerRadius()
public int getIntrinsicWidth()
Drawable
Intrinsic width is the width at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic width, such as a solid color, this method returns -1.
getIntrinsicWidth
in class Drawable
public int getIntrinsicHeight()
Drawable
Intrinsic height is the height at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic height, such as a solid color, this method returns -1.
getIntrinsicHeight
in class Drawable
public 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 Drawable
PixelFormat