我需要画一条从A点(x1,y1)到B点(x2,y2)的线。但是,不仅仅是显示线,我需要看到实际绘制的线 - 从A点到B点,以可控的速度一点一点地绘制。我已经为此尝试了警报和循环,但无法找到我的解决方案我正在研究表面视图。请为此提供解决方案
答案 0 :(得分:3)
private int startX = 0;
private int startY = 0;
private int endX = 0;
private int endY = 0;
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG) {
{
setDither(true);
setColor(Color.RED);
}
};
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawLine(startX, startY, endX, endY, paint);
if (endX != 300 && endY != 300) { // set end points
endY++;
endX++;
postInvalidateDelayed(15); // set time here
}
}