给定一个闭合路径对象的结果是这样的:

“在这里输入的图像描述”

虽然这是我在寻找一些与任何闭合路径工作的矩形。

有帮助吗?

解决方案

虽然steelbytes的回答可能让您欣赏到梯度的各个部分更多的控制,你可以不用路径:

protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
    Paint p = new Paint();
    // start at 0,0 and go to 0,max to use a vertical
    // gradient the full height of the screen.
    p.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
    canvas.drawPaint(p);
}

其他提示

这可以帮助

protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
    int w = getWidth();
    int h = getHeight();
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
    Path pth = new Path();
    pth.moveTo(w*0.27f,0);
    pth.lineTo(w*0.73f,0);
    pth.lineTo(w*0.92f,h);
    pth.lineTo(w*0.08f,h);
    pth.lineTo(w*0.27f,0);
    p.setColor(0xff800000);
    p.setShader(new LinearGradient(0,0,0,h,0xff000000,0xffffffff,Shader.TileMode.CLAMP));
    canvas.drawPath(pth,p);
}   
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top