Android DrawArc SweepGradient over 360 °

I am trying to create a color wheel that allows the user to choose between solid color or gradients. The user can also move these colors around the wheel.

The problem is with the gradient. When the angle exceeds 360 °, the displayed color reverts to the first color instead of continuing the gradient.

I am using a custom view and the code I am inserting is called from the onDraw method.

int start = Color.rgb((int)previous.startRed, (int)previous.startGreen, (int)previous.startBlue);
int end = Color.rgb((int)previous.endRed, (int)previous.endGreen, (int)previous.endBlue);
int[] colors = {start, end, end};
float from = from_angle / 360.0f;
float to = (from_angle + to_angle) / 360.0f;
float[] positions = {from,to, to};
Log.v("Print", "print positions " + positions[0] + " " + positions[1]);
Shader gradient = new SweepGradient (oval.centerX(), oval.centerY(),colors, positions);
paint.setShader(gradient);
canvas.drawArc(oval, from_angle, to_angle + 1, false, paint);

      

Here is an image to show the problem I am facing. enter image description here

Any hint would be appreciated. Thank.

+3
android android-custom-view


source to share


No one has answered this question yet

Check out similar questions:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
1296
Reloading activity on android rotation
915
Running / installing / debugging Android apps over Wi-Fi?



All Articles
Loading...
X
Show
Funny
Dev
Pics