Added in API level 1

PictureDrawable


open class PictureDrawable : Drawable
kotlin.Any
   ↳ android.graphics.drawable.Drawable
   ↳ android.graphics.drawable.PictureDrawable

Drawable subclass that wraps a Picture, allowing the picture to be used wherever a Drawable is supported.

Summary

Public constructors

Construct a new drawable referencing the specified picture.

Public methods
open Unit
draw(canvas: Canvas)

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

open Int

Returns the drawable's intrinsic height.

open Int

Returns the drawable's intrinsic width.

open Int

Return the opacity/transparency of this Drawable.

open Picture!

Return the picture associated with the drawable.

open Unit
setAlpha(alpha: Int)

Specify an alpha value for the drawable.

open Unit
setColorFilter(colorFilter: ColorFilter?)

Specify an optional color filter for the drawable.

open Unit
setPicture(picture: Picture!)

Associate a picture with this drawable.

Inherited functions

Public constructors

PictureDrawable

Added in API level 1
PictureDrawable(picture: Picture!)

Construct a new drawable referencing the specified picture. The picture may be null.

Parameters
picture Picture!: The picture to associate with the drawable. May be null.

Public methods

draw

Added in API level 1
open fun draw(canvas: Canvas): Unit

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

Parameters
canvas Canvas: The canvas to draw into.
This value cannot be null.

getIntrinsicHeight

Added in API level 1
open fun getIntrinsicHeight(): Int

Returns the drawable's intrinsic height.

Intrinsic height is the height at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic height, such as a solid color, this method returns -1.

Return
Int the intrinsic height, or -1 if no intrinsic height

getIntrinsicWidth

Added in API level 1
open fun getIntrinsicWidth(): Int

Returns the drawable's intrinsic width.

Intrinsic width is the width at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic width, such as a solid color, this method returns -1.

Return
Int the intrinsic width, or -1 if no intrinsic width

getOpacity

Added in API level 1
open fun getOpacity(): Int

Return the opacity/transparency of this Drawable. The returned value is one of the abstract format constants in android.graphics.PixelFormat: android.graphics.PixelFormat#UNKNOWN, android.graphics.PixelFormat#TRANSLUCENT, android.graphics.PixelFormat#TRANSPARENT, or android.graphics.PixelFormat#OPAQUE.

An OPAQUE drawable is one that draws all all content within its bounds, completely covering anything behind the drawable. A TRANSPARENT drawable is one that draws nothing within its bounds, allowing everything behind it to show through. A TRANSLUCENT drawable is a drawable in any other state, where the drawable will draw some, but not all, of the content within its bounds and at least some content behind the drawable will be visible. If the visibility of the drawable's contents cannot be determined, the safest/best return value is TRANSLUCENT.

Generally a Drawable should be as conservative as possible with the value it returns. For example, if it contains multiple child drawables and only shows one of them at a time, if only one of the children is TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be returned. You can use the method resolveOpacity to perform a standard reduction of two opacities to the appropriate single output.

Note that the returned value does not necessarily take into account a custom alpha or color filter that has been applied by the client through the setAlpha or #setColorFilter methods. Some subclasses, such as BitmapDrawable, ColorDrawable, and GradientDrawable, do account for the value of setAlpha, but the general behavior is dependent upon the implementation of the subclass.

Return
Int int The opacity class of the Drawable.
Value is one of the following:

getPicture

Added in API level 1
open fun getPicture(): Picture!

Return the picture associated with the drawable. May be null.

Return
Picture! the picture associated with the drawable, or null.

setAlpha

Added in API level 1
open fun setAlpha(alpha: Int): Unit

Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.

Parameters
alpha Int: Value is between 0 and 255 inclusive

setColorFilter

Added in API level 1
open fun setColorFilter(colorFilter: ColorFilter?): Unit

Specify an optional color filter for the drawable.

If a Drawable has a ColorFilter, each output pixel of the Drawable's drawing contents will be modified by the color filter before it is blended onto the render target of a Canvas.

Pass null to remove any existing color filter.

Note: Setting a non-null color filter disables tint.

Parameters
colorFilter ColorFilter?: The color filter to apply, or null to remove the existing color filter

setPicture

Added in API level 1
open fun setPicture(picture: Picture!): Unit

Associate a picture with this drawable. The picture may be null.

Parameters
picture Picture!: The picture to associate with the drawable. May be null.