如何在Android上绘制下一个东西之前暂停5秒?
假设我想画一条线,然后等待五秒钟,然后再画另一条线。我有一个这样的方法:
public void onDraw(Canvas canvas) {
int w = canvas.getWidth();
int h = canvas.getHeight();
canvas.drawLine(w/2, 0, w/2, h-1, paint);
// PAUSE FIVE SECONDS
canvas.drawLine(0, h/2, w-1, h/2, paint);
}
如何暂停?
Say I want to draw a line, then wait five seconds, then draw another line. I have a method like this:
public void onDraw(Canvas canvas) {
int w = canvas.getWidth();
int h = canvas.getHeight();
canvas.drawLine(w/2, 0, w/2, h-1, paint);
// PAUSE FIVE SECONDS
canvas.drawLine(0, h/2, w-1, h/2, paint);
}
How do I pause?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用这样的 CountDownTimer :
问候,
you can use a CountDownTimer like this :
Regards,
不要在 UI 线程中调用 onDraw 方法中等待,否则您将阻止它。使用标志来处理将绘制哪条线
而不是像这样在代码中使用它
Don't wait in onDraw method it's called in the UI thread and you'll block it. Use flags to handle which line will be drawn
Than use it in your code like this
嗯...您可以在(这将在其他方法中)设置一个标志,并在您的 onDraw() 中根据该标志的值绘制该线。
即也许类似(虽然我不确定为什么你需要暂停)
Well... you could set a flag in (which would be in some other method) and within your
onDraw()
based on the value of this flag draw that line.i.e. maybe something like (though I'm not sure why you would need a pause)
使用 Thread.sleep(5000) 就可以了。
Use
Thread.sleep(5000)
, that should do it.