我有一个由一些设计师创建的gif,我们想要在使用Web服务作为" loading"动画,但我找不到怎么做,我发现InfinitProgress你可以使用图像个性化,动画旋转它,但在这种情况下我们需要的动画不是旋转而是形状改变,有什么办法吗?做到了吗?
答案 0 :(得分:2)
要在您的Codename One项目中使用动画Gif,您需要此库:https://github.com/codenameone/AnimatedGifSupport/
另见这篇关于该库的文章: https://www.codenameone.com/blog/animated-gif-support.html
不要手动下载库,打开项目的“Codename One”设置,单击Extensions,然后单击“动画Gif支持”的“下载”。看这个截图:
答案 1 :(得分:1)
尝试以下注释代码,也许它会按照您的要求执行:
Form hi = new Form("Hi World", BoxLayout.y());
// Replace the "loadingIcon" with the animated gif that you want
Label loadingIcon = new Label(FontImage.createMaterial(FontImage.MATERIAL_3D_ROTATION, "Label", 5));
loadingIcon.getAllStyles().setBgTransparency(0);
Dialog loadingAnimation = new Dialog();
loadingAnimation.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
Style dlgStyle = loadingAnimation.getDialogStyle();
dlgStyle.setBorder(Border.createEmpty());
dlgStyle.setBgTransparency(0);
loadingAnimation.add(BorderLayout.CENTER, loadingIcon);
Button doTask = new Button("Tap here to do a task");
doTask.addActionListener(l -> {
loadingAnimation.showModeless();
Log.p("Some tasks simulated by a sleep of five seconds");
// Remove the UITimer and add your network tasks
// Call loadingAnimation.dispose() when the tasks are ended
new UITimer(() -> {
loadingAnimation.dispose();
}).schedule(5000, false, loadingAnimation);
});
hi.add(doTask);
hi.show();