1

I am drawing a radial gradient as a glow effect for selection. Everything was working until I drew another circle on top of the gradient. First off, here is my gradient and code:

Radial gradient. Note that the size and position are set dynamically, so the values here are meaningless:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <gradient
        android:endColor="#0025AAE1"
        android:gradientRadius="0"
        android:startColor="#FF25AAE1"
        android:type="radial" />

    <size
        android:height="5dp"
        android:width="5dp" />
</shape>

And now my drawing code.

Initialized in the constructor:

circle = (GradientDrawable)context.getResources().getDrawable(R.drawable.test_gradient);

Drawing code: public void draw(Canvas canvas, Thumb thumb) { float x = thumb.getX(); float y = thumb.getY();

    paint.setColor(borderColor);
    canvas.drawCircle(x, y, radius, paint);

    paint.setColor(centerColor);
    canvas.drawCircle(x, y, radius - radiusBorder, paint);

    if (thumb.isSelected())
    {
        int circleRadius = radius + 10;
        circle.setGradientRadius(circleRadius);
        circle.setBounds((int)x - circleRadius, (int)y - circleRadius, (int)x + circleRadius, (int)y + circleRadius);
        circle.draw(canvas);

                    // This circle causes issues!
        paint.setColor(selectedCenterColor);
        canvas.drawCircle(x, y, radius - (radiusBorder * 2), paint);
    }
} 

If the problem drawCircle() line is commented out, the gradient appears as I'd expect: gradient is OK

When I run with the drawCircle() enabled, it appears as this: enter image description here

What happened to the gradient? How can it be affected by drawing something else on top of it? The newly-drawn circle is smaller than the gradient and is one solid color. I don't understand what could be happening here.

Mark Herscher
  • 1,761
  • 2
  • 19
  • 32

0 Answers0