用渐变绘制线条

rgu*_*rra 3 android canvas line

我有多条线画在不同的位置.例如:

canvas.drawLine(startXLine1 ,stopXLine1, startYLine1, stopYLine1, paint)
canvas.drawLine(startXLine2 ,stopXLine2, startYLine2, stopYLine2, paint)
Run Code Online (Sandbox Code Playgroud)

我希望每行都有这样的渐变: 在此输入图像描述

当我尝试这个时,我没有这个效果,但是这个方向的渐变蓝色(左)--->白色(右)像这样:http://media.24ways.org/2011/verou/1. PNG

Shader shader = new LinearGradient(startXLine1, startYLine1, stopXLine1, stopYLine1, res.getColor(R.color.blue),  res.getColor(R.color.white), Shader.TileMode.CLAMP);

paint.setShader(shader);
Run Code Online (Sandbox Code Playgroud)

有人可以帮我这个吗?

bon*_*nyz 6

要像你的图像一样填充背景:

Shader shader = new LinearGradient(0, 0, 0, h /*canvas height*/, res.getColor(R.color.blue),  res.getColor(R.color.white), Shader.TileMode.MIRROR /*or REPEAT*/);

paint.setShader(shader);
Run Code Online (Sandbox Code Playgroud)