RoundedBitmapDrawable
public abstract class RoundedBitmapDrawable extends Drawable
| java.lang.Object | ||
| ↳ | android.graphics.drawable.Drawable | |
| ↳ | androidx.core.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 android.graphics.Bitmap object.
Also see the android.graphics.Bitmap class, which handles the management and transformation of raw bitmap graphics, and should be used when drawing to a android.graphics.Canvas.
Summary
Public methods |
|
|---|---|
void |
|
int |
getAlpha() |
final @Nullable Bitmap |
Returns the bitmap used by this drawable to render. |
ColorFilter |
|
float |
|
int |
Get the gravity used to position/stretch the bitmap within its bounds. |
int |
|
int |
|
int |
This method is deprecated. |
final @NonNull Paint |
getPaint()Returns the paint used to render this drawable. |
boolean |
Indicates whether anti-aliasing is enabled for this drawable. |
boolean |
Indicates whether the mipmap hint is enabled on this drawable's bitmap. |
boolean |
|
void |
setAlpha(int alpha) |
void |
setAntiAlias(boolean aa)Enables or disables anti-aliasing for this drawable. |
void |
setCircular(boolean circular)Sets the image shape to circular. |
void |
|
void |
setCornerRadius(float cornerRadius)Sets the corner radius to be applied when drawing the bitmap. |
void |
setDither(boolean dither)This method is deprecated. |
void |
setFilterBitmap(boolean filter) |
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(@NonNull 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. |
void |
setTargetDensity(@NonNull DisplayMetrics metrics)Set the density scale at which this drawable will be rendered. |
Protected methods |
|
|---|---|
void |
onBoundsChange(@NonNull Rect bounds) |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public methods
getBitmap
public final @Nullable Bitmap getBitmap()
Returns the bitmap used by this drawable to render. May be null.
getCornerRadius
public float getCornerRadius()
| Returns | |
|---|---|
float |
The corner radius applied when drawing the bitmap. |
getGravity
public int getGravity()
Get the gravity used to position/stretch the bitmap within its bounds.
| Returns | |
|---|---|
int |
the gravity applied to the bitmap |
| See also | |
|---|---|
Gravity |
getPaint
public final @NonNull Paint getPaint()
Returns the paint used to render this drawable.
hasAntiAlias
public boolean hasAntiAlias()
Indicates whether anti-aliasing is enabled for this drawable.
| Returns | |
|---|---|
boolean |
True if anti-aliasing is enabled, false otherwise. |
| See also | |
|---|---|
setAntiAlias |
hasMipMap
public 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 | |
|---|---|
setMipMap |
isCircular
public boolean isCircular()
| Returns | |
|---|---|
boolean |
|
setAntiAlias
public 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 | |
|---|---|
boolean aa |
True if the bitmap should be anti-aliased, false otherwise. |
| See also | |
|---|---|
hasAntiAlias |
setCircular
public void setCircular(boolean circular)
Sets the image shape to circular.
This overwrites any calls made to setCornerRadius so far.
setCornerRadius
public void setCornerRadius(float cornerRadius)
Sets the corner radius to be applied when drawing the bitmap.
setGravity
public void setGravity(int gravity)
Set the gravity used to position/stretch the bitmap within its bounds.
| Parameters | |
|---|---|
int gravity |
the gravity |
| See also | |
|---|---|
Gravity |
setMipMap
public void setMipMap(boolean mipMap)
Enables or disables the mipmap hint for this drawable's bitmap. See setHasMipMap 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 | |
|---|---|
boolean mipMap |
True if the bitmap should use mipmaps, false otherwise. |
| See also | |
|---|---|
hasMipMap |
setTargetDensity
public void setTargetDensity(@NonNull 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.
| See also | |
|---|---|
setDensity |
|
getDensity |
setTargetDensity
public void setTargetDensity(int density)
Set the density at which this drawable will be rendered.
| Parameters | |
|---|---|
int density |
The density scale for this drawable. |
| See also | |
|---|---|
setDensity |
|
getDensity |
setTargetDensity
public void setTargetDensity(@NonNull DisplayMetrics metrics)
Set the density scale at which this drawable will be rendered.
| Parameters | |
|---|---|
@NonNull DisplayMetrics metrics |
The DisplayMetrics indicating the density scale for this drawable. |
| See also | |
|---|---|
setDensity |
|
getDensity |