Issa
10/25/2020, 4:39 PMBox(modifier = Modifier.height(100.dp).width(100.dp).drawBehind {
HorizontalGradient(
0.0f to Color.Red,
0.5f to Color.Green,
1.0f to Color.Blue,
startX = 0.0f,
endX = 100.0f
)
})Issa
10/25/2020, 4:41 PMheight and width i am setting on the exampleAdam Powell
10/25/2020, 6:05 PMHorizontalGradient is a factory function for a gradient Brush. It's returning an object that you are not using. Save it in a val and use it as a Brush argument to one or more draw* functions in the drawBehind block.Adam Powell
10/25/2020, 6:08 PMdrawWithCache to give yourself a place to create brushes and similar once, or only when they change, rather than every time it draws:
Modifier.drawWithCache {
val brush = HorizontalGradient(...)
onDraw {
drawCircle(brush, ...)
}
}Se7eN
10/25/2020, 6:33 PMsize from the DrawScope for the width or height for your startX or endXIssa
10/25/2020, 7:29 PMIssa
10/25/2020, 7:30 PM