如何填补Android的一个路径的线性梯度?梯度、线性、路径、Android

2023-09-03 20:30:13 作者:心劫

由于封闭路径对象的结果是这样的:

Given a closed Path object result is like this:

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

Although that is a rectangle I'm looking for something which works with any closed Path.

推荐答案

虽然steelbytes的回答可能让您欣赏到渐变的各个部分更多的控制,你可以做到这一点不带路径:

While steelbytes' answer will probably give you more control over the individual sections of the gradient, you can do it without the path:

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);
}