added in version 26.1.0
belongs to Maven artifact


public class RoundedDrawable
extends Drawable


Maintains and draws a drawable inside rounded rectangular bounds.

The drawable set by the setDrawable(Drawable) method will be drawn within the rounded bounds specified by setBounds(Rect) and setRadius(int) when the draw(Canvas) method is called.

By default, RoundedDrawable will apply padding to the drawable inside to fit the drawable into the rounded rectangle. If clipping is enabled by the setClipEnabled(boolean) method, it will clip the drawable to a rounded rectangle instead of resizing it.

The setRadius(int) method is used to specify the amount of border radius applied to the corners of inner drawable, regardless of whether or not the clipping is enabled, border radius will be applied to prevent overflowing of the drawable from specified rounded rectangular area.

RoundedDrawable can be inflated from XML (supported above API level 24) or constructed programmatically. To inflate from XML, use getDrawable(int) method.


 <?xml version="1.0" encoding="utf-8"?>
   app:clipEnabled="boolean" />


XML attributes


Public constructors


Public methods

void draw(Canvas canvas)
int getAlpha()
int getBackgroundColor()

Returns the background color.

Drawable getDrawable()

Returns the drawable that will be rendered.

int getOpacity()
int getRadius()

Returns the border radius applied when rendering the drawable in pixels.

void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
boolean isClipEnabled()

Returns whether the drawable inside is clipped or resized to fit the rounded bounds.

void setAlpha(int alpha)
void setBackgroundColor(int color)

Sets the background color of the rounded drawable.

void setClipEnabled(boolean clipEnabled)

Sets whether the drawable inside should be clipped or resized to fit the rounded bounds.

void setColorFilter(ColorFilter cf)
void setDrawable(Drawable drawable)

Sets the drawable to be rendered.

void setRadius(int radius)

Sets the border radius to be applied when rendering the drawable in pixels.

Protected methods

void onBoundsChange(Rect bounds)

Inherited methods

From class