延迟显示管理器中的字段(黑莓)
我有一个循环向管理器添加字段,我试图延迟每个字段绘制到屏幕上之间的时间。我一直在尝试下面的代码,但它只是在所有字段都添加到其中后才绘制管理器。 这可能吗?
manager.add(field);
manager.invalidate();//force a repaint of the manager
Thread.sleep(1000);
谢谢
I have a loop adding fields to a manager, I am trying to delay the time between when each field is painted onto the screen. I have been trying below code but it just paints the manager when all fields have been added to it.
Is this possible ?
manager.add(field);
manager.invalidate();//force a repaint of the manager
Thread.sleep(1000);
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无效并不一定会强制绘制,它只是表示在下一次绘制时需要重新绘制字段(或您的情况下的管理器)。这是一个微妙的差异,但可能会引起混乱。您可能想要尝试的是调用 Screen.doPaint() ,这将强制重新绘制整个屏幕。另外,将 sleep() 放在事件线程中不会有帮助,因为绘画也是在同一个线程上完成的。
如果您尝试在第二次延迟的情况下按顺序向管理器添加字段,则应将此逻辑放入其自己的线程中,并在执行时执行
synchronized(UiApplication.getEventLock()){//add fields}
调用manager.add(field)。然后你可以调用你的 Thread.sleep(1000) 来正确地延迟显示。另外,就像一些添加的信息一样,调用add()
本质上会导致 invalidate() 调用,因此您不需要添加它。这是添加第二次延迟的简单示例绘制应该在 add() 之后发生,但如果没有发生,您也可以调用
yourScreen.doPaint()
Invalidate doesn't necessarily force a paint, it simply says that on the next paint the Field (or Manager in your case) needs to be redrawn. It's a subtle difference but it could be causing the confusion. What you might want to try is calling
Screen.doPaint()
, which will force the entire screen to redraw. Also, putting the sleep() in your Event Thread won't help, because painting is also done on the same Thread.If you are trying to sequentially add Fields to your Manager with this second delay, you should put this logic in its own Thread and do
synchronized(UiApplication.getEventLock()){//add fields}
when you call manager.add(field). Then you can call yourThread.sleep(1000)
to correctly have the delay in displaying. Also, just as a some added info, callingadd()
inherently causes an invalidate() call, so you don't need to add it. Here's a simple example of the second delay in addingThe painting should occur after the add(), but if it doesn't you can also make a call to
yourScreen.doPaint()