我在 Codename One 上实现了一个带有动画文本序列的启动屏幕。我不想在 Splash Form 上使用 nextForm 属性,因为我希望在导航之前完成序列。因此,我使用了showForm。它在模拟器上运行良好,但当我在真实设备上测试时,以编程方式加载的下一个表单需要时间来加载,转换很慢,有时会崩溃。我似乎无法弄清楚为什么......
我已包含以下示例代码:
@Override
protected void beforeSplash(Form f) {
// If the resource file changes the names of components this call will break notifying you that you should fix the code
super.beforeSplash(f);
final String text = "Sample text to be animated here for testing purpose!";
final SpanLabel l = findSloganLabel(f);
Animation anim = new Animation() {
private long lastTime = System.currentTimeMillis();
public boolean animate() {
long t = System.currentTimeMillis();
int i = l.getText().length();
if (t - lastTime >= 450) {
if (i == text.length()) {
showForm("Register", null);
return false;
} else {
System.out.println("Animating Label...");
if (i == text.length() - 1) {
l.setText(text);
l.revalidate();
} else {
l.setText(text.substring(0, i) + "_");
l.revalidate();
}
}
lastTime = t;
}
return false;
}
public void paint(Graphics g) {
}
};
f.registerAnimated(anim);
}
最佳答案
你可以这样做:
@Override
protected void postSplash(Form f) {
UITimer timer = new UITimer(new Runnable() {
public void run() {
showForm("MainForm", null);
}
});
timer.schedule(XX-MiliSec, false, f);
}
所以在你的初始表单的 postForm 方法中添加计时器.. 并将其安排在 XX 毫秒后(无论您的动画持续时间是多少)
它将在提到的毫秒后执行 showForm() 方法
关于java - 代号一 - 仅在启动屏幕上的动画完成后才显示下一个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28050486/