public
abstract
class
RoundedBitmapDrawable
extends Drawable
java.lang.Object | ||
↳ | android.graphics.drawable.Drawable | |
↳ | android.support.v4.graphics.drawable.RoundedBitmapDrawable |
A Drawable that wraps a bitmap and can be drawn with rounded corners. You can create a
RoundedBitmapDrawable from a file path, an input stream, or from a
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
.
Public methods | |
---|---|
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. |
final
Bitmap
|
getBitmap()
Returns the bitmap used by this drawable to render. |
ColorFilter
|
getColorFilter()
Returns the current color filter, or |
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. |
final
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()
|
void
|
setAlpha(int alpha)
Specify an alpha value for the drawable. |
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)
This method is deprecated. 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
|
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(DisplayMetrics metrics)
Set the density scale at which this drawable will be rendered. |
void
|
setTargetDensity(Canvas canvas)
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. |
Protected methods | |
---|---|
void
|
onBoundsChange(Rect bounds)
Override this in your subclass to change appearance if you vary based on the bounds. |
Inherited methods | |
---|---|
From
class
android.graphics.drawable.Drawable
| |
From
class
java.lang.Object
|
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).
Parameters | |
---|---|
canvas |
Canvas :
The canvas to draw into
|
int getAlpha ()
Gets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque. This method is implemented by Drawable subclasses and the value returned is specific to how that class treats alpha. The default return value is 255 if the class does not override this method to return a value specific to its use of alpha.
Returns | |
---|---|
int |
Bitmap getBitmap ()
Returns the bitmap used by this drawable to render. May be null.
Returns | |
---|---|
Bitmap |
ColorFilter getColorFilter ()
Returns the current color filter, or null
if none set.
Returns | |
---|---|
ColorFilter |
the current color filter, or null if none set
|
float getCornerRadius ()
Returns | |
---|---|
float |
The corner radius applied when drawing the bitmap. |
int getGravity ()
Get the gravity used to position/stretch the bitmap within its bounds.
Returns | |
---|---|
int |
the gravity applied to the bitmap |
See also:
int getIntrinsicHeight ()
Returns the drawable's intrinsic height.
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.
Returns | |
---|---|
int |
the intrinsic height, or -1 if no intrinsic height |
int getIntrinsicWidth ()
Returns the drawable's intrinsic width.
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.
Returns | |
---|---|
int |
the intrinsic width, or -1 if no intrinsic width |
int getOpacity ()
Return the opacity/transparency of this Drawable. The returned value is
one of the abstract format constants in
PixelFormat
:
UNKNOWN
,
TRANSLUCENT
,
TRANSPARENT
, or
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 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 setAlpha(int)
or setColorFilter(ColorFilter)
methods. Some subclasses,
such as BitmapDrawable
, ColorDrawable
, and GradientDrawable
,
do account for the value of setAlpha(int)
, but the general behavior is dependent
upon the implementation of the subclass.
Returns | |
---|---|
int |
int The opacity class of the Drawable. |
boolean hasAntiAlias ()
Indicates whether anti-aliasing is enabled for this drawable.
Returns | |
---|---|
boolean |
True if anti-aliasing is enabled, false otherwise. |
See also:
boolean hasMipMap ()
Indicates whether the mipmap hint is enabled on this drawable's bitmap.
Returns | |
---|---|
boolean |
True if the mipmap hint is set, false otherwise. If the bitmap is null, this method always returns false. |
See also:
boolean isCircular ()
Returns | |
---|---|
boolean |
true if the image is circular, else false .
|
void setAlpha (int alpha)
Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.
Parameters | |
---|---|
alpha |
int
|
void setAntiAlias (boolean aa)
Enables or disables anti-aliasing for this drawable. Anti-aliasing affects the edges of the bitmap only so it applies only when the drawable is rotated.
Parameters | |
---|---|
aa |
boolean :
True if the bitmap should be anti-aliased, false otherwise. |
See also:
void setCircular (boolean circular)
Sets the image shape to circular.
This overwrites any calls made to setCornerRadius(float)
so far.
Parameters | |
---|---|
circular |
boolean
|
void setColorFilter (ColorFilter cf)
Specify an optional color filter for the 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
.
Parameters | |
---|---|
cf |
ColorFilter :
The color filter to apply, or null to remove the
existing color filter
|
void setCornerRadius (float cornerRadius)
Sets the corner radius to be applied when drawing the bitmap.
Parameters | |
---|---|
cornerRadius |
float
|
void setDither (boolean dither)
This method is deprecated.
This property is ignored.
Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component.
Parameters | |
---|---|
dither |
boolean
|
void setFilterBitmap (boolean filter)
Set to true to have the drawable filter its bitmaps with bilinear sampling when they are scaled or rotated.
This can improve appearance when bitmaps are rotated. If the drawable does not use bitmaps, this call is ignored.
Parameters | |
---|---|
filter |
boolean
|
void setGravity (int gravity)
Set the gravity used to position/stretch the bitmap within its bounds.
Parameters | |
---|---|
gravity |
int :
the gravity |
See also:
void setMipMap (boolean mipMap)
Enables or disables the mipmap hint for this drawable's bitmap.
See 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.
Parameters | |
---|---|
mipMap |
boolean :
True if the bitmap should use mipmaps, false otherwise. |
See also:
void setTargetDensity (DisplayMetrics metrics)
Set the density scale at which this drawable will be rendered.
Parameters | |
---|---|
metrics |
DisplayMetrics :
The DisplayMetrics indicating the density scale for this drawable. |
See also:
void setTargetDensity (Canvas canvas)
Set the density scale at which this drawable will be rendered. This method assumes the drawable will be rendered at the same density as the specified canvas.
Parameters | |
---|---|
canvas |
Canvas :
The Canvas from which the density scale must be obtained. |
See also:
void setTargetDensity (int density)
Set the density at which this drawable will be rendered.
Parameters | |
---|---|
density |
int :
The density scale for this drawable. |
See also:
void onBoundsChange (Rect bounds)
Override this in your subclass to change appearance if you vary based on the bounds.
Parameters | |
---|---|
bounds |
Rect
|