RoundedDrawable

open class RoundedDrawable : Drawable
kotlin.Any
   ↳ android.graphics.drawable.Drawable
   ↳ androidx.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 android.content.Context#getDrawable(int) method.

Syntax:
 <?xml version="1.0" encoding="utf-8"?> <androidx.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

Public constructors

Public methods
open Boolean

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

open Unit
draw(canvas: Canvas)

open Unit
setRadius(radius: Int)

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

open Int

open Unit
setAlpha(alpha: Int)

open Int

open Drawable?

Returns the drawable that will be rendered.

open Unit
inflate(r: Resources, parser: XmlPullParser, attrs: AttributeSet, theme: Theme?)

open Unit

Sets the background color of the rounded drawable.

open Int

Returns the background color.

open Unit
setClipEnabled(clipEnabled: Boolean)

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

open Unit

open Unit
setDrawable(drawable: Drawable?)

Sets the drawable to be rendered.

open Int

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

Protected methods
open Unit
onBoundsChange(bounds: Rect!)

Public constructors

<init>

RoundedDrawable()

Public methods

isClipEnabled

open fun isClipEnabled(): Boolean

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

Return
Boolean: true if the drawable is clipped, false if it's resized.

draw

open fun draw(canvas: Canvas): Unit

setRadius

open fun setRadius(radius: Int): Unit

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

Parameters
radius Int: radius in pixels

getAlpha

open fun getAlpha(): Int

setAlpha

open fun setAlpha(alpha: Int): Unit

getOpacity

open fun getOpacity(): Int

getDrawable

open fun getDrawable(): Drawable?

Returns the drawable that will be rendered.

Return
Drawable?: Drawable that will be rendered.

inflate

open fun inflate(r: Resources, parser: XmlPullParser, attrs: AttributeSet, theme: Theme?): Unit

setBackgroundColor

open fun setBackgroundColor(color: Int): Unit

Sets the background color of the rounded drawable.

Parameters
color Int: an ARGB color

getBackgroundColor

open fun getBackgroundColor(): Int

Returns the background color.

Return
Int: an ARGB color

setClipEnabled

open fun setClipEnabled(clipEnabled: Boolean): Unit

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.

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

setColorFilter

open fun setColorFilter(cf: ColorFilter!): Unit

setDrawable

open fun setDrawable(drawable: Drawable?): Unit

Sets the drawable to be rendered.

Parameters
drawable Drawable?: Drawable to be rendered

getRadius

open fun getRadius(): Int

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

Return
Int: radius in pixels

Protected methods

onBoundsChange

protected open fun onBoundsChange(bounds: Rect!): Unit