Android 12 Developer Preview is here! Try it out, and give us your feedback!

androidx.compose.ui.draw

Interfaces

BuildDrawCacheParams

The set of parameters which could be used to build the drawing cache.

DrawCacheModifier

DrawModifier implementation that supports building a cache of objects to be referenced across draw calls

DrawModifier

A Modifier.Element that draws into the space of the layout.

Classes

CacheDrawScope

Handle to a drawing environment that enables caching of content based on the resolved size.

DrawResult

Holder to a callback to be invoked during draw operations.

Extension functions summary

For Modifier
Modifier

Draw content with modified alpha that may be less than 1.

Modifier

Clip the content to shape.

Modifier

Clip the content to the bounds of a layer defined at this modifier.

Modifier
Modifier.drawBehind(onDraw: DrawScope.() -> Unit)

Draw into a Canvas behind the modified content.

Modifier
Modifier.drawWithCache(onBuildDrawCache: CacheDrawScope.() -> DrawResult)

Draw into a DrawScope with content that is persisted across draw calls as long as the size of the drawing area is the same or any state objects that are read have not changed.

Modifier

Creates a DrawModifier that allows the developer to draw before or after the layout's contents.

Modifier
Modifier.paint(painter: Painter, sizeToIntrinsics: Boolean = true, alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Inside, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null)

Paint the content using painter.

Modifier
Modifier.rotate(degrees: Float)

Sets the degrees the view is rotated around the center of the composable.

Modifier
Modifier.scale(scaleX: Float, scaleY: Float)

Scale the contents of the composable by the following scale factors along the horizontal and vertical axis respectively.

Modifier

Scale the contents of both the horizontal and vertical axis uniformly by the same scale factor.

Modifier
Modifier.shadow(elevation: Dp, shape: Shape = RectangleShape, clip: Boolean = elevation > 0.dp)

Creates a GraphicsLayerModifier that draws the shadow.

Extension functions

alpha

@Stable fun Modifier.alpha(alpha: Float): Modifier

Draw content with modified alpha that may be less than 1.

Usage of this API renders this composable into a separate graphics layer

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.size
import androidx.compose.ui.draw.alpha

Box(Modifier.size(100.dp).alpha(alpha = 0.5f).background(Color.Red))

See Also

Parameters
alpha: Float the fraction of children's alpha value and must be between 0 and 1, inclusive.

clip

@Stable fun Modifier.clip(shape: Shape): Modifier

Clip the content to shape.

Parameters
shape: Shape the content will be clipped to this Shape.

clipToBounds

@Stable fun Modifier.clipToBounds():