java - 代号一 - 仅在启动屏幕上的动画完成后才显示下一个表单

标签 java android java-me codenameone

我在 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/

相关文章:

Java:反向排序而不保持顺序

android - 在适配器内进行一些网络操作

java-me - J2ME诺基亚s40内存不足异常

java - J2ME : UI framework

java - 将 JavaME 移植到 Android

java - 要在您的应用程序中查看网页?

java - 如何使用java替换Json中的字符串

java - 如何从Java中的主类访问src.test包或如何从主类运行测试类?

android - 无法在 Mac 上的 Android Studio 上创建虚拟设备

android - 从 JCenter 迁移到 mavenCentral 存储库时出现 Gradle 问题