Skip to content

Most visited

Recently visited

navigation
added in version 26.1.0
belongs to Maven artifact com.android.support:wear:27.0.0

RoundedDrawable

public class RoundedDrawable
extends Drawable

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.support.wear.widget.RoundedDrawable


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.

Syntax:

 <?xml version="1.0" encoding="utf-8"?>
 <android.support.wear.widget.RoundedDrawable
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:src="drawable"
   app:backgroundColor="color"
   app:radius="dimension"
   app:clipEnabled="boolean" />

Summary

XML attributes

RoundedDrawable_android_src  
RoundedDrawable_backgroundColor  
RoundedDrawable_clipEnabled  
RoundedDrawable_radius  

Public constructors

RoundedDrawable()

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 android.graphics.drawable.Drawable
From class java.lang.Object

XML attributes

RoundedDrawable_android_src

Related methods:

RoundedDrawable_backgroundColor

Related methods:

RoundedDrawable_clipEnabled

Related methods:

RoundedDrawable_radius

Related methods:

Public constructors

RoundedDrawable

added in version 26.1.0
RoundedDrawable ()

Public methods

draw

added in version 26.1.0
void draw (Canvas canvas)

Parameters
canvas Canvas

getAlpha

int getAlpha ()

Returns
int

getBackgroundColor

added in version 26.1.0
int getBackgroundColor ()

Returns the background color.

Returns
int an ARGB color

getDrawable

added in version 26.1.0
Drawable getDrawable ()

Returns the drawable that will be rendered.

Returns
Drawable Drawable that will be rendered.

getOpacity

added in version 26.1.0
int getOpacity ()

Returns
int

getRadius

added in version 26.1.0
int getRadius ()

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

Returns
int radius in pixels

inflate

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

Parameters
r Resources

parser XmlPullParser

attrs AttributeSet

theme Resources.Theme

Throws
XmlPullParserException
IOException

isClipEnabled

added in version 26.1.0
boolean isClipEnabled ()

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

Returns
boolean true if the drawable is clipped, false if it's resized.

setAlpha

added in version 26.1.0
void setAlpha (int alpha)

Parameters
alpha int

setBackgroundColor

added in version 26.1.0
void setBackgroundColor (int color)

Sets the background color of the rounded drawable.

Related XML Attributes:

Parameters
color int: an ARGB color

setClipEnabled

added in version 26.1.0
void setClipEnabled (boolean clipEnabled)

Sets whether the drawable inside should be clipped or resized to fit the rounded bounds. If the drawable is animated, don't set clipping to true as clipping on animated drawables is not supported.

Related XML Attributes:

Parameters
clipEnabled boolean: true if the drawable should be clipped, false if it should be resized.

setColorFilter

added in version 26.1.0
void setColorFilter (ColorFilter cf)

Parameters
cf ColorFilter

setDrawable

added in version 26.1.0
void setDrawable (Drawable drawable)

Sets the drawable to be rendered.

Related XML Attributes:

Parameters
drawable Drawable: Drawable to be rendered

setRadius

added in version 26.1.0
void setRadius (int radius)

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

Related XML Attributes:

Parameters
radius int: radius in pixels

Protected methods

onBoundsChange

void onBoundsChange (Rect bounds)

Parameters
bounds Rect

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)