我想将动画图像或视频添加到我的启动画面。它应该适合不同设备的屏幕尺寸。起初,我尝试添加一个.mp4,它工作正常,但我无法获得正确的转换(在转到下一个表单前显示黑色矩形)。所以我改变了时间表,将gif添加到.res文件并试图绘制它。没有什么我试过的,我没有选择,所以我想我会问是否有更好的方法。Codename One:将时间线设置为背景图片
选项1:设置BG
protected void beforeVideoSplash(Form f) {
super.beforeVideoSplash(f);
FormFactory.modifyBaseForm(f);
Timeline splashGif = null;
try {
splashGif = (Timeline) Resources.openLayered("/theme").getImage("vNewSplash480x360.gif");
} catch (IOException e) {
}
f.getAllStyles().setBgImage(splashGif);
}
结果:模拟器显示白屏。在Android设备(平板电脑和手机)上崩溃。
选项2:对玻璃板油漆
protected void beforeVideoSplash(Form f) {
super.beforeVideoSplash(f);
FormFactory.modifyBaseForm(f);
f.setGlassPane(new Painter() {
public void paint(Graphics g, Rectangle rect) {
Timeline splashGif = null;
try {
splashGif = (Timeline) Resources.openLayered("/theme").getImage("vNewSplash480x360.gif");
} catch (IOException e) {
}
splashGif.requiresDrawImage();
Display display = Display.getInstance();
int imgWidth = display.getDisplayWidth();
int imageHeight = 320 * display.getDisplayWidth()/480;
g.drawImage(splashGif, 0, (display.getDisplayHeight() - imageHeight)/2, imgWidth, imageHeight);
}
}
);
}
结果:白色屏幕上模拟器和Android设备。
方案3:扩展
不重复自己,我缩放图像,像这样:
Image scaled;
Display display = Display.getInstance();
if (display.getDisplayWidth() > display.getDisplayHeight()) {
scaled = splashGif.scaledWidth(display.getDisplayHeight());
} else {
scaled = splashGif.scaledWidth(display.getDisplayWidth());
}
然后用BorderLayout的带有中心约束它添加到标签的容器内。
结果:这种方式实际上工作,但应用程序运行速度太慢,可能是由于缩放和生成图像的大小。
方案4:设置中心行为
使用的BorderLayout想尽中心的行为(和无行为,只是把它尝试过)。添加图像作为标签图标。
结果:图片没有缩放,加上它出现在屏幕的左侧,而不是中间。
不记得我是否错过了一个选项,在任何情况下,所有选项都可以正常使用从jpgs或pngs加载的静态图像,是Timeline的问题吗?
有没有办法实际制作动画启动画面? (我不反对使用视频,在这种情况下,我需要让控件消失,并且最终的过渡是瞬间的,使用定时器和完成回调尝试,都显示一个黑色的矩形视频大小之前转换)
谢谢Shai,是的,我意识到requireDrawImage()只是在那天晚些时候返回一个布尔值,当我把它放入时,我正在一个“让我们尝试任何东西”的框架。 –