The canvas.drawpath not work for me

930 Views Asked by At
    int size = 500;
    int xInterval = 30;

    for (int i = 0; i < size; i++) {
        float x = xInterval * i;
        float y = (float) (Math.random() * 300);

        if (i == 0) {
            mLinePath.moveTo(x, y);
        } else {
            mLinePath.lineTo(x, y);
        }

        canvas.drawText(i + "", x, y, mTextPaint);
    }

    canvas.drawPath(mLinePath, mLinePaint);

I put the codes above in the onDraw method but the path was not shown, the text was shown, I have doubt that whether the point size were too large? How can I solve this problem? And the code of the paints initialized:

    mLinePaint = new Paint();
    mLinePaint.setAntiAlias(true);
    mLinePaint.setDither(true);
    mLinePaint.setStyle(Paint.Style.STROKE);
    mLinePaint.setColor(Color.WHITE);

    mTextPaint = new Paint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setDither(true);
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setColor(Color.WHITE);
0

There are 0 best solutions below