I am trying to draw a gradient background in Jetpack Compose, and I would like the gradient to have a fixed angle regardless of the shape of the object I'm drawing into.
However, using Modifier.background(brush=...)
, the best I can find is linearGradient
which calculates the angle from a fixed start and end point of a gradient.
For example, is there a way I can specify that I want a 45 degree angle for my gradient without knowing the final size it's going to be?
Edit: I would like a solution that can work for any given angle, not just 45 degrees.
You can use the parameters start
and end
to achieve a 45 degree angle.
Something like:
val gradient45 = Brush.linearGradient(
colors = listOf(Color.Yellow, Color.Red),
start = Offset(0f, Float.POSITIVE_INFINITY),
end = Offset(Float.POSITIVE_INFINITY, 0f)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With