我试图慢慢地向android画布绘制点数。我想使用canvas.drawline函数,但是绘制一个点到另一个我希望有小延迟。你能帮帮我吗?
答案 0 :(得分:0)
以下是一般模式:
// PSEUDOCODE
// in a class created in a Looper thread, e.g., the main thread
private final Handler handler = new Handler();
static class DrawTask implements Runnable {
// final fields for start point, end point, number of segments, interval, etc.
// mutable field for progress
// constructor with appropriate params
@Override
public void run() {
// draw the current line segment
if(!finished) {
handler.postDelayed(this, interval);
}
}
}
// in some draw method
handler.post(new DrawTask(...));
您可能希望挂起对DrawTask的引用,这样您就可以使用Handler#removeCallbacks(...)
取消它,以防在您的活动暂停时它仍在运行。