caelum19
05/25/2020, 6:11 PMBox(
modifier = Modifier
.preferredSize(500.dp, 500.dp)
.drawBackground(
HorizontalGradient(
0.0f to Color.Red,
0.5f to Color.Green,
1.0f to Color.Blue,
startX = Px.Zero,
endX = 500.dp.toPx()
)
)
)
I'd like for a gradient's end to match the parent's width - is there a nicer way to do this?Zach Klippenstein (he/him) [MOD]
05/25/2020, 8:21 PMWithConstraints
Kazemihabib1996
05/26/2020, 2:23 PMBox(
modifier = Modifier
.fillMaxSize() // for example
.plus(
object : DrawModifier {
override fun ContentDrawScope.draw() {
drawRect(
HorizontalGradient(
0.0f to Color.Red,
0.5f to Color.Green,
1.0f to Color.Blue,
startX = Px.Zero,
endX = size.width.toDp().toPx()
)
)
drawContent()
}
}
)
)
caelum19
05/28/2020, 9:44 PMWithConstraints() {
Box(
modifier = Modifier
.preferredSize(500.dp, 500.dp)
.drawBackground(
HorizontalGradient(
0.0f to Color.Red,
0.3f to Color.Green,
1.0f to Color.Blue,
startX = Px.Zero,
endX = constraints.maxWidth.toPx()
)
)
) {
}
}
Ali Kabiri
08/17/2021, 9:27 AMval gradient = Brush.horizontalGradient(
colors = listOf(
startColor,
endColor
),
startX = 0f,
endX = size.value * 2.625f * fill
)
Box(
modifier = Modifier
.background(
brush = gradient
)
) {}
caelum19
08/19/2021, 10:58 AM