Search code examples
androidandroid-canvasgradientandroid-guigeometric-arc

Android: draw arc within canvas api with a gradient fill color


I want to draw an arc using canvas using a gradient fill. How can achieve this?


Solution

  • Hey I stole this from here: Draw an arc with a SweepGradient in Android

    but it works fine, I used a LinearGradient instead.

    Shader gradient = new SweepGradient (0,getMeasuredHeight()/2, Color.RED, Color.WHITE);
    lightRed.setShader(gradient);
    canvas.drawArc(rectf, -90, 360, false, lightRed);