1

I have a ShapeDrawable Object in my class in the form of an arc.

ShapeDrawable progressArc = new ShapeDrawable(new ArcShape(120, 12));

Now I would like to use a radial gradient effect on the color and also display just a ring instead of a filled arc. Does the Android SDK provide such a feature?

Currently using the below code, I get a gradient on the circle.

progressArc.setIntrinsicHeight(500);
progressArc.setIntrinsicWidth(500);

Shader shader1 = new LinearGradient(5, -5, 35, 0, new int[] { 0xFF33B5E5,0xFFFFFFFF }, null, Shader.TileMode.MIRROR);
progressArc.getPaint().setShader(shader1);
progressArc.getPaint().setStrokeWidth(1);
progressArc.getPaint().setColor(Color.RED);
progressArc.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
4

1 回答 1

4

您可以使用 aSweepGradient来获得径向渐变:

Shader s = new SweepGradient(0, 0, new int[] { 0xFF33B5E5,0xFFFFFFFF }, null);
//or if you only use two colors:
Shader s = new SweepGradient(0, 0, 0xFF33B5E5, 0xFFFFFFFF);

为避免填充,只需使用Paint.Style.STROKE样式,并带有适当的strokeWidth.

于 2013-01-10T22:15:39.523 回答