如何在画布上同时绘制线条并擦除前一行[android]

时间:2016-02-11 12:33:34

标签: android canvas

我正在使用画布。

我正在尝试同时绘制线条并擦除上一行,但它隐藏在绘制线后面。所以我想连续画线并删除前一行。缺少什么,我该如何解决?欢迎任何帮助。

Here is a screen of the application

public class DrawView extends View {
Paint paint = new Paint();
Path mPath, mPathErase;
Paint PaintWhite = new Paint();
float Rectpx, RectgetScanBarWidth, RectgetHeight;
int cnvasHight;
int cnvasWidth;


public DrawView(Context context) {
    super(context);
    paint.setColor(Color.GREEN);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.MITER);
    paint.setStrokeWidth(2f);
    mPath = new Path();
    mPathErase = new Path();

    PaintWhite.setColor(Color.WHITE);
    PaintWhite.setStyle(Paint.Style.STROKE);
    PaintWhite.setStrokeJoin(Paint.Join.MITER);
    PaintWhite.setStrokeWidth(4f);


}


public ContextObject plotingProcedure(ContextObject drow, float py) {
    System.out.println("counter:=" + Float.parseFloat(drow.getCounter().toString()) + " PX:-" + drow.getPx() + " Py:-" + drow.getPy());
    Rectpx = drow.getPx();
    RectgetScanBarWidth = drow.getScanBarWidth();
    RectgetHeight = drow.getHeight();
    drow.setPx(Float.parseFloat(drow.getCounter().toString()));
    drow.setPy(py);
    System.out.println("Rect Dim" + Rectpx + " , " + RectgetScanBarWidth + " , " + RectgetHeight);
    mPath.moveTo(drow.getOpx(), drow.getOpy());
    mPath.lineTo(drow.getPx(), drow.getPy());

    drow.setOpx(drow.getPx());
    drow.setOpy(drow.getPy());

    if (drow.getOpx() > drow.getWidth()) {
        drow.setPx(0);
        drow.setOpx(0);
        drow.setCounter(0d);
    } else {
        System.out.println("counter after:======" + drow.getCounter());
        drow.setCounter(drow.getCounter() + drow.getSpeed());
    }
    drow.setCurrentsample(drow.getCurrentsample() + 1);


    invalidate();
    return drow;
}

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(5);
    canvas.drawRect(Rectpx, 0, Rectpx + RectgetScanBarWidth, RectgetHeight, paint);
    paint.setColor(Color.GREEN);
    paint.setStrokeWidth(5);
    canvas.drawPath(mPath, paint);
}

public int getCanvasHeigt() {
    return cnvasHight;
}

public void setCanvasHeigt(int cnvasHight) {
    this.cnvasHight = cnvasHight;
}

public int getCanvasWidth() {
    return cnvasWidth;
}

public void setCanvasWidth(int width) {
    this.cnvasWidth = width;
}

}

1 个答案:

答案 0 :(得分:-1)

您需要在绘制新行之前清除画布,以便使用Link

中说明的方法