代号一并发动画?
Codename one concurrent animations?
在代号一中,我有一个像 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 是主 class 的一个字段。我还尝试将添加包装在 Display.getInstance().callSerially(() -> {code here}) 中,但它也没有用。
我如何处理并发动画?
您应该使用 AnimationManager.flushAnimation 来 post 您的动画。当所有其他动画完成时,这将导致动画为 运行。这应该可以解决冲突。
在代号一中,我有一个像 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 是主 class 的一个字段。我还尝试将添加包装在 Display.getInstance().callSerially(() -> {code here}) 中,但它也没有用。 我如何处理并发动画?
您应该使用 AnimationManager.flushAnimation 来 post 您的动画。当所有其他动画完成时,这将导致动画为 运行。这应该可以解决冲突。