【问题标题】:Codename one concurrent animations?代号一并发动画?
【发布时间】:2016-09-01 23:57:03
【问题描述】:

在 Codename One 中,我有一个类似 UI 的简单聊天,并希望使用 animateLayout 添加消息(标签)。如果消息之间有时间或者动画时间很短,它可以正常工作,但是当两个动画重叠时,第二个组件没有动画。这是我尝试过的代码(把它放在新的代号一个项目启动方法中):

    Form hi = new Form("Hi World");
    hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    Button button = new Button("Add");
    Label label = new Label("Status");

    button.addActionListener((actionEvent) -> {
        hi.getContentPane().add("asd");
        hi.getContentPane().animateLayout(3000);
    });

    hi.add(button);
    hi.show();

我希望将 animateLayout 更改为 animateLayoutAndWait 会解决这个问题,但它没有。我也尝试了旧的解决方法:

    Form hi = new Form("Hi World");
    hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    Button button = new Button("Add");
    Label label = new Label("Status");

    button.addActionListener((actionEvent) -> {
        if(!animateLock) {
            animateLock = true;
            hi.getContentPane().add("asd");
            hi.getContentPane().animateLayout(3000);
            animateLock = false;
        }
    });

    hi.add(button);
    hi.show();

其中 animateLock 是主类的一个字段。我还尝试将添加包装在 Display.getInstance().callSerially(() -> {code here}) 中,但它也不起作用。 如何处理并发动画?

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    您应该使用AnimationManager.flushAnimation 发布您的动画。这将导致动画在所有其他动画完成后运行。这应该可以解决冲突。

    【讨论】:

    • form.getAnimationManager().flushAnimation() 完成了这项工作!
    • 仅供参考,您也可以使用animateLayoutAndWait() 修复上面的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多