当paint设置为fill时,canvas.drawPath什么都不绘制?

时间:2012-07-19 15:22:23

标签: java android android-canvas

我正在尝试使用drawPath()在画布上绘制一个三角形,但我在填充三角形时遇到问题。如果我将绘制设置为STROKE,则下面的代码将绘制三角形,但是当它设置为FILL时,它不会绘制任何内容。我在这里做错了吗?

    labelArrowBox.reset();

    labelArrowBox.moveTo(labelPosition.x, labelPosition.y);

    float x = labelPosition.x + LABEL_BOX_ARROW_WIDTH / 2;
    float y = labelPosition.y - LABEL_BOX_ARROW_HEIGHT;
    labelArrowBox.lineTo(x, y);
    labelArrowBox.moveTo(x, y);

    x = labelPosition.x - LABEL_BOX_ARROW_WIDTH / 2;
    labelArrowBox.lineTo(x, y);
    labelArrowBox.moveTo(x, y);

    labelArrowBox.lineTo(labelPosition.x, labelPosition.y);
    labelArrowBox.moveTo(labelPosition.x, labelPosition.y);

    labelArrowBox.close();

    Paint arrowBorderPaint = new Paint();
    arrowBorderPaint.setAntiAlias(true);
    arrowBorderPaint.setDither(true);
    arrowBorderPaint.setColor(getContext().getResources().getColor(R.color.leaf_thin_ring));
    arrowBorderPaint.setStyle(Paint.Style.FILL);

    canvas.drawPath(labelArrowBox, arrowBorderPaint);

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。移除moveTo()您只需要lineTo()您不应该需要这些内容:labelArrowBox.moveTo(x, y);