简体   繁体   English

Android:从顶部绘制带有渐变的弧线

[英]Android: draw arc with gradient from top

The gradient starts from 3 o'clock - however I want it to start from 12. 渐变从3点开始-但是我希望它从12点开始。

 int color1 = Color.RED;
 int color2 = Color.BLUE;
 int[] colors = {color1, color2};
 Shader gradient = new SweepGradient(width / 2, height / 2, colors, null);
 mArcPaint.setShader(gradient);

Any suggestions on how to rotate the start to 12? 关于如何将起点旋转到12的任何建议? I tried with 我尝试过

 Matrix matrix = new Matrix();
 matrix.postRotate(270f);
 gradient.setLocalMatrix(matrix);

but it did not work for me. 但这对我没有用。

You need to specify Rotate pointX, pointY 您需要指定旋转pointX,pointY
In your case: 在您的情况下:

Matrix matrix = new Matrix();
matrix.postRotate(270f,width / 2, height / 2);
gradient.setLocalMatrix(matrix);

I use shader draw Circle for showing different case below 我使用着色器绘制圆圈在下面显示不同的情况

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM