Brush
@Immutable sealed class Brush
kotlin.Any | |
↳ | androidx.compose.ui.graphics.Brush |
Summary
Public methods | |
---|---|
open Unit | |
abstract Unit |
Companion functions | |
---|---|
Brush |
horizontalGradient(colors: List<Color>, startX: Float = 0.0f, endX: Float = Float.POSITIVE_INFINITY, tileMode: TileMode = TileMode.Clamp) Creates a horizontal gradient with the given colors evenly dispersed within the gradient |
Brush |
horizontalGradient(vararg colorStops: ColorStop, startX: Float = 0.0f, endX: Float = Float.POSITIVE_INFINITY, tileMode: TileMode = TileMode.Clamp) Creates a horizontal gradient with the given colors dispersed at the provided offset defined in the ColorStop |
Brush |
linearGradient(vararg colorStops: ColorStop, start: Offset = Offset.Zero, end: Offset = Offset.Infinite, tileMode: TileMode = TileMode.Clamp) Creates a linear gradient with the provided colors along the given start and end coordinates. |
Brush |
linearGradient(colors: List<Color>, start: Offset = Offset.Zero, end: Offset = Offset.Infinite, tileMode: TileMode = TileMode.Clamp) Creates a linear gradient with the provided colors along the given start and end coordinates. |
Brush |
radialGradient(vararg colorStops: ColorStop, center: Offset = Offset.Unspecified, radius: Float = Float.POSITIVE_INFINITY, tileMode: TileMode = TileMode.Clamp) Creates a radial gradient with the given colors at the provided offset defined in the ColorStop |
Brush |
radialGradient(colors: List<Color>, center: Offset = Offset.Unspecified, radius: Float = Float.POSITIVE_INFINITY, tileMode: TileMode = TileMode.Clamp) Creates a radial gradient with the given colors evenly dispersed within the gradient |
Brush |
sweepGradient(vararg colorStops: ColorStop, center: Offset = Offset.Unspecified) Creates a sweep gradient with the given colors dispersed around the center with offsets defined in each ColorStop. |
Brush |
sweepGradient(colors: List<Color>, center: Offset = Offset.Unspecified) Creates a sweep gradient with the given colors dispersed evenly around the center. |
Brush |
verticalGradient(colors: List<Color>, startY: Float = 0.0f, endY: Float = Float.POSITIVE_INFINITY, tileMode: TileMode = TileMode.Clamp) Creates a vertical gradient with the given colors evenly dispersed within the gradient Ex: |
Brush |
verticalGradient(vararg colorStops: ColorStop, startY: Float = 0f, endY: Float = Float.POSITIVE_INFINITY, tileMode: TileMode = TileMode.Clamp) Creates a vertical gradient with the given colors at the provided offset defined in the ColorStop |
Public methods
Companion functions
horizontalGradient
@Stable fun horizontalGradient(
colors: List<Color>,
startX: Float = 0.0f,
endX: Float = Float.POSITIVE_INFINITY,
tileMode: TileMode = TileMode.Clamp
): Brush
Creates a horizontal gradient with the given colors evenly dispersed within the gradient
Ex:
Brush.horizontalGradient( listOf(Color.Red, Color.Green, Color.Blue), startX = 10.0f, endX = 20.0f )
import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.wrapContentSize Column(modifier = Modifier.fillMaxSize().wrapContentSize()) { // Create a linear gradient that shows red in the top left corner // and blue in the bottom right corner val linear = Brush.linearGradient(listOf(Color.Red, Color.Blue)) Box(modifier = Modifier.size(120.dp).background(linear)) Spacer(modifier = Modifier.size(20.dp)) // Create a radial gradient centered about the drawing area that is green on // the outer // edge of the circle and magenta towards the center of the circle val radial = Brush.radialGradient(listOf(Color.Green, Color.Magenta)) Box(modifier = Modifier.size(120.dp).background(radial)) Spacer(modifier = Modifier.size(20.dp)) // Create a radial gradient centered about the drawing area that is green on // the outer // edge of the circle and magenta towards the center of the circle val sweep = Brush.sweepGradient(listOf(Color.Cyan, Color.Magenta)) Box(modifier = Modifier.size(120.dp).background(sweep)) }
Parameters | |
---|---|
colors: List<Color> | colors Colors to be rendered as part of the gradient |
startX: Float = 0.0f | Starting x position of the horizontal gradient. Defaults to 0 which represents the left of the drawing area |
endX: Float = Float.POSITIVE_INFINITY | Ending x position of the horizontal gradient. Defaults to Float.POSITIVE_INFINITY which indicates the right of the specified drawing area |
tileMode: TileMode = TileMode.Clamp | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
horizontalGradient
@Stable fun horizontalGradient(
vararg colorStops: ColorStop,