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

PathEffect

interface PathEffect
androidx.compose.ui.graphics.PathEffect

Effect applied to the geometry of a drawing primitive. For example, this can be used to draw shapes as a dashed or shaped pattern, or apply a treatment around line segment intersections.

Summary

Companion functions
PathEffect

Create a PathEffect that applies the inner effect to the path, and then applies the outer effect to the result of the inner effect.

PathEffect

Replaces sharp angles between line segments into rounded angles of the specified radius

PathEffect
dashPathEffect(intervals: FloatArray, phase: Float = 0f)

Draws a shape as a series of dashes with the given intervals and offset into the specified interval array.

PathEffect
stampedPathEffect(shape: Path, advance: Float, phase: Float, style: StampedPathEffectStyle)

Dash the drawn path by stamping it with the specified shape represented as a Path.

Extension functions
From androidx.compose.ui.graphics
PathEffect

Companion functions

chainPathEffect

fun chainPathEffect(
    outer: PathEffect,
    inner: PathEffect
): PathEffect

Create a PathEffect that applies the inner effect to the path, and then applies the outer effect to the result of the inner effect. (e.g. outer(inner(path)).

cornerPathEffect

fun cornerPathEffect(radius: Float): PathEffect

Replaces sharp angles between line segments into rounded angles of the specified radius

Parameters
radius: Float Rounded corner radius to apply for each angle of the drawn shape

dashPathEffect

fun dashPathEffect(
    intervals: FloatArray,
    phase: Float = 0f
): PathEffect

Draws a shape as a series of dashes with the given intervals and offset into the specified interval array. The intervals must contain an even number of entries (>=2). The even indices specify "on" intervals and the odd indices represent "off" intervals. The phase parameter is the pixel offset into the intervals array (mod the sum of all of the intervals).

For example: if intervals[] = {10, 20}, and phase = 25, this will set up a dashed path like so: 5 pixels off 10 pixels on 20 pixels off 10 pixels on 20 pixels off

The phase parameter is an offset into the intervals array. The intervals array controls the length of the dashes. This is only applied for stroked shapes (ex. PaintingStyle.Stroke and is ignored for filled in shapes (ex. PaintingStyle.Fill

Parameters
intervals: FloatArray Array of "on" and "off" distances for the dashed line segments
phase: Float = 0f Pixel offset into the intervals array

stampedPathEffect

fun stampedPathEffect(
    shape: Path,
    advance: Float,
    phase: Float,
    style: StampedPathEffectStyle
): PathEffect

Dash the drawn path by stamping it with the specified shape represented as a Path. This is only applied to stroke shapes and will be ignored with filled shapes. The stroke width used with this PathEffect is ignored as well.

Parameters
shape: Path Path to stamp along
advance: Float Spacing between each stamped shape
phase: Float Amount to offset before the first shape is stamped
style: StampedPathEffectStyle How to transform the shape at each position as it is stamped