I am trying to draw elliptical gradients as well a...
# compose
m
I am trying to draw elliptical gradients as well as radial ones. What would be the best approach to implement something like this? The
RadialGradient
allows only one radius in the definition.
n
Do you have a mock of what you are trying to build? We added support for 2 focal point radial gradients in Android 12. If you would like to leverage this in compose you can create a
ShaderBrush
that creates an instance of this gradient for devices running Android 12+. https://developer.android.com/reference/android/graphics/RadialGradient#RadialGradient(float,%20float,%20flo[…],%20android.graphics.Shader.TileMode) Depending on the implementation you might be able to do so with multiple RadialGradient implementations with a ComposeShader in Android.
m
I want to create the following type of gradient so that I can place text in the lower right corner over the background graphic.
The Android version is 9 (Pie).
n
So we currently don't have support for matrix transformations of shaders in compose, however you can create an android.graphics.RadialGradient with a horizontal scale applied to a matrix passed to
setLocalMatrix
and wrap this with a
ShaderBrush
to get the desired effect