RoundedDrawable

Added in 1.1.0

class RoundedDrawable : Drawable


Maintains and draws a drawable inside rounded rectangular bounds.

The drawable set by the setDrawable method will be drawn within the rounded bounds specified by setBounds and setRadius when the draw 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 method, it will clip the drawable to a rounded rectangle instead of resizing it.

The setRadius 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 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 functions

Unit
draw(canvas: Canvas)
Int
@ColorInt Int

Returns the background color.

Drawable?

Returns the drawable that will be rendered.

Int

This function is deprecated.

Int

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

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

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

Unit
setAlpha(alpha: Int)
Unit

Sets the background color of the rounded drawable.

Unit
setClipEnabled(clipEnabled: Boolean)

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

Unit
Unit
setDrawable(drawable: Drawable?)

Sets the drawable to be rendered.

Unit
setRadius(radius: Int)

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

Protected functions

Unit
onBoundsChange(bounds: Rect!)

Inherited functions

From android.graphics.drawable.Drawable
Unit
Boolean
Unit
Rect!
Unit
copyBounds(bounds: Rect!)
java-static Drawable!
createFromPath(pathName: String!)
java-static Drawable!
createFromResourceStream(
    res: Resources!,
    value: TypedValue!,
    is: InputStream!,
    srcName: String!
)
java-static Drawable!
createFromStream(is: InputStream!, srcName: String!)
java-static Drawable!
java-static Drawable!
createFromXmlInner(
    r: Resources!,
    parser: XmlPullParser!,
    attrs: AttributeSet!
)
Rect!
Drawable.Callback!
Int
ColorFilter!
Drawable.ConstantState!
Drawable!
Rect!
Unit
Int
Int
Int
Int
Int
Int
Insets!
Unit
getOutline(outline: Outline!)
Boolean
getPadding(padding: Rect!)
IntArray<Int>!
Region!
Boolean
Unit
inflate(r: Resources!, parser: XmlPullParser!, attrs: AttributeSet!)
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Drawable!
Boolean
onLayoutDirectionChanged(layoutDirection: Int)
Boolean
Boolean
java-static Int
resolveOpacity(op1: Int, op2: Int)
Unit
scheduleSelf(what: Runnable!, when: Long)
Unit
Unit
setBounds(left: Int, top: Int, right: Int, bottom: Int)
Unit
Unit
Unit
setDither(dither: Boolean)

This function is deprecated.

Unit
Unit
Unit
setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int)
Boolean
setLayoutDirection(layoutDirection: Int)
Boolean
setLevel(level: Int)
Boolean
setState(stateSet: IntArray!)
Unit
setTint(tintColor: Int)
Unit
Unit
Unit
Boolean
setVisible(visible: Boolean, restart: Boolean)
Unit

Public constructors

RoundedDrawable

Added in 1.1.0
RoundedDrawable()

Public functions

draw

Added in 1.1.0
fun draw(canvas: Canvas): Unit

getAlpha

fun getAlpha(): Int

getBackgroundColor

Added in 1.1.0
fun getBackgroundColor(): @ColorInt Int

Returns the background color.

Returns
@ColorInt Int

an ARGB color

getDrawable

Added in 1.1.0
fun getDrawable(): Drawable?

Returns the drawable that will be rendered.

Returns
Drawable?

Drawable that will be rendered.

getOpacity

Added in 1.1.0
fun getOpacity(): Int

getRadius

Added in 1.1.0
fun getRadius(): Int

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

Returns
Int

radius in pixels

inflate

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

isClipEnabled

Added in 1.1.0
fun isClipEnabled(): Boolean

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 1.1.0
fun setAlpha(alpha: Int): Unit

setBackgroundColor

Added in 1.1.0
fun setBackgroundColor(color: @ColorInt Int): Unit

Sets the background color of the rounded drawable.

Parameters
color: @ColorInt Int

an ARGB color backgroundColor

setClipEnabled

Added in 1.1.0
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. clipEnabled

setColorFilter

Added in 1.1.0
fun setColorFilter(cf: ColorFilter?): Unit

setDrawable

Added in 1.1.0
fun setDrawable(drawable: Drawable?): Unit

Sets the drawable to be rendered.

Parameters
drawable: Drawable?

Drawable to be rendered src

setRadius

Added in 1.1.0
fun setRadius(radius: Int): Unit

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

Parameters
radius: Int

radius in pixels radius

Protected functions

onBoundsChange

protected fun onBoundsChange(bounds: Rect!): Unit