2016-03-04 54 views
3

我想將動畫圖像或視頻添加到我的啓動畫面。它應該適合不同設備的屏幕尺寸。起初,我嘗試添加一個.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的問題嗎?

有沒有辦法實際製作動畫啓動畫面? (我不反對使用視頻,在這種情況下,我需要讓控件消失,並且最終的過渡是瞬間的,使用定時器和完成回調嘗試,都顯示一個黑色的矩形視頻大小之前轉換)

回答

0

似乎有一個迴歸那裏。我們將修復它以便進行下一次更新。

您不需要撥打requiresDrawImage(),因爲它是我們在內部使用的回調。你選擇的第一種方法應該工作得很好。

+0

謝謝Shai,是的,我意識到requireDrawImage()只是在那天晚些時候返回一個布爾值,當我把它放入時,我正在一個「讓我們嘗試任何東西」的框架。 –