请在下次指定是在Android浏览器上是指Android应用画布还是HTML5画布。如果是前者,请使用android-canvas。此解决方案在JS中使用,因为它更易于展示,并且可以在任一平台上正常工作。
画布中沿路径的渐变很难。最简单的方法是捏造它。
与其将图像视为遵循圆形路径的渐变,不如将其视为两个线性渐变。
想象一下由这两个渐变组成的正方形:

现在想象一个切入的圆:

那就是你要做的。
像这样“剪切”它最容易使用剪切区域,因此我举了一个例子。
这是实时示例:http : //jsfiddle.net/simonsarris/Msdkv/
代码如下:
var greenPart = ctx.createLinearGradient(0,0,0,100);
greenPart.addColorStop(0, 'palegreen');
greenPart.addColorStop(1, 'lightgray');
var whitePart = ctx.createLinearGradient(0,0,0,100);
whitePart.addColorStop(0, 'white');
whitePart.addColorStop(1, 'lightgray');
var width = 20;
ctx.lineWidth = width;
// First we make a clipping region for the left half
ctx.save();
ctx.beginPath();
ctx.rect(-width, -width, 50+width, 100 + width*2);
ctx.clip();
// Then we draw the left half
ctx.strokeStyle = greenPart;
ctx.beginPath();
ctx.arc(50,50,50,0,Math.PI*2, false);
ctx.stroke();
ctx.restore(); // restore clipping region to default
// Then we make a clipping region for the right half
ctx.save();
ctx.beginPath();
ctx.rect(50, -width, 50+width, 100 + width*2);
ctx.clip();
// Then we draw the right half
ctx.strokeStyle = whitePart;
ctx.beginPath();
ctx.arc(50,50,50,0,Math.PI*2, false);
ctx.stroke();
ctx.restore(); // restore clipping region to default
Run Code Online (Sandbox Code Playgroud)