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 | |
---|---|
<init>() |
Public methods | |
---|---|
open Unit | |
open Int |
getAlpha() |
open Int |
Returns the background color. |
open Drawable? |
Returns the drawable that will be rendered. |
open Int | |
open Int |
Returns the border radius applied when rendering the drawable in pixels. |
open Unit |
inflate(@NonNull r: Resources, @NonNull parser: XmlPullParser, @NonNull attrs: AttributeSet, @Nullable theme: Theme?) |
open Boolean |
Returns whether the drawable inside is clipped or resized to fit the rounded bounds. |
open Unit | |
open Unit |
setBackgroundColor(@ColorInt color: Int) Sets the background color of the rounded drawable. |
open Unit |
setClipEnabled(clipEnabled: Boolean) Sets whether the drawable inside should be clipped or resized to fit the rounded bounds. |
open Unit |
setColorFilter(cf: ColorFilter?) |
open Unit |
setDrawable(@Nullable drawable: Drawable?) Sets the drawable to be rendered. |
open Unit |
Sets the border radius to be applied when rendering the drawable in pixels. |
Protected methods | |
---|---|
open Unit |
onBoundsChange(bounds: Rect!) |
Public constructors
<init>
RoundedDrawable()
Public methods
getAlpha
open fun getAlpha(): Int
getBackgroundColor
@ColorInt open fun getBackgroundColor(): Int
Returns the background color.
Return | |
---|---|
Int |
an ARGB color |
getDrawable
@Nullable open fun getDrawable(): Drawable?
Returns the drawable that will be rendered.
Return | |
---|---|
Drawable? |
Drawable that will be rendered. |
getOpacity
open fun getOpacity(): Int
getRadius
open fun getRadius(): Int
Returns the border radius applied when rendering the drawable in pixels.
Return | |
---|---|
Int |
radius in pixels |
inflate
open fun inflate(
@NonNull r: Resources,
@NonNull parser: XmlPullParser,
@NonNull attrs: AttributeSet,
@Nullable theme: Theme?
): Unit
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. |
setBackgroundColor
open fun setBackgroundColor(@ColorInt color: Int): Unit
Sets the background color of the rounded drawable.
Parameters | |
---|---|
color |
Int: an ARGB color androidx.wear.R.attr#backgroundColor |
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. androidx.wear.R.attr#clipEnabled |
setColorFilter
open fun setColorFilter(cf: ColorFilter?): Unit
setDrawable
open fun setDrawable(@Nullable drawable: Drawable?): Unit
Sets the drawable to be rendered.
Parameters | |
---|---|
drawable |
Drawable?: Drawable to be rendered android.R.attr#src |
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 androidx.wear.R.attr#radius |