I need to paint the background of my Canvas one color with shading/gradient applied, but each onDraw call I would like to potentially change the color.
I am having trouble doing this without creating a new object each onDraw call. Anyone have any ideas? If I use drawPaint() and set a new shader() to my paint, then I have created a new shader object and if I create a new GradientDrawable() I have as well. I want to avoid GC.
I thought I could reuse one GradientDrawable() object and call the .setColor() method, but this just resets any gradient data associated it and paints the drawable as that solid color.
Anyone?
Unfortunately you have to create a new LinearGradient everytime. Note that you don't have to use a GradientDrawable, you can draw the shape yourself with a Paint on which you set the shader.
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