2012-01-12 180 views
2

我正在爲我的BlackBerry應用程序創建啓動屏幕。現在圖像沒有正確放置在我測試的所有模擬器中。 啓動畫面的圖像大小應該是多少,以便適合所有設備尺寸?初始屏幕圖像大小

+1

列出您願意支持的設備,然後列出它們的屏幕尺寸。並創建具有尺寸的圖像(所有屏幕寬度的最小寬度,所有屏幕高度的最小高度)。然後,您可以將其垂直居中放置。你也可以使用任何圖像並使用'Bitmap.scaleInto(params)'在運行時調整它們的大小。 – Rupak 2012-01-12 08:15:45

回答

4

的主要部分是,創建啓動類延伸UIApplication的

這是StartUp.java

public class StartUp extends UiApplication 
{ 
public static void main(String[]args) 
{ 
    StartUp start=new StartUp(); 
    start.enterEventDispatcher(); 
} 
public StartUp() 
{ 
    this.pushScreen(new SplashScreen()); 
    invokeLater(new Runnable() 
    { 
     public void run() 
     { 
      try 
      { 
       Thread.sleep(2000);// Sleeps it for few seconds 
       UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); 
       pushScreen(new LoadingScreen()); 
      } 
      catch (Exception e) 
      { 
       exceptionHandling(e.getMessage()); 
      } 
     } 
    }); 

} 

public static void exceptionHandling(final String exception) 
{ 
    UiApplication.getUiApplication().invokeLater(new Runnable() 
    {  
     public void run() 
     { 
      Dialog.alert(exception); 
     } 
    }); 
} 
} 

SplashScreen.java

public class SplashScreen extends MainScreen 
{ 
Bitmap bitmap=Bitmap.getBitmapResource("loading-screen.png");//This is my company logo; 
BitmapField loadingImage=new BitmapField(bitmap); 
public SplashScreen() 
{ 
    createGUI(); 
} 

private void createGUI() 
{ 
    try 
    { 
     VerticalFieldManager vertical=new VerticalFieldManager() 
     { 
      protected void paint(Graphics g) 
      { 
       g.drawBitmap(0, 0,Display.getWidth(),Display.getHeight(), bitmap, 0, 0); 
       super.paint(g); 
      } 
      protected void sublayout(int maxWidth, int maxHeight) 
      { 
       super.sublayout(Display.getWidth(),Display.getHeight()); 
       setExtent(Display.getWidth(),Display.getHeight()); 
      } 
     }; 

    //   Nothing to write; 

     add(vertical); 
    } 
    catch (Exception e) 
    { 
     StartUp.exceptionHandling(e.getMessage()); 
    } 
} 
} 

和你FirstScreen.java

public class FirstScreen extends MainScreen 
{ 
VerticalFieldManager vertical; 

public FirstScreen() 
{    
    createGUI(); 
} 

private void createGUI() 
{ 
    setTitle("Loading Screen"); 
    vertical=new VerticalFieldManager() 
    { 
     protected void sublayout(int maxWidth, int maxHeight) 
     { 
      super.sublayout(Display.getWidth(),Display.getHeight()); 
      setExtent(Display.getWidth(),Display.getHeight()); 
     } 
    }; 
    add(vertical); 
} 

public boolean onMenu(int instance) 
{ 
    return true; 
} 
} 

試試這個你可以得到。

1

只需像400X400任何圖像,並把該圖像到您的項目的res文件夾。

然後 在啓動畫面類文件中,您可以調整圖像的寬度,設備的高度爲&。

Bitmap splashImage = Bitmap.getBitmapResource("Splash.png");//your splash screen's name with it's extension if it is PNG then .png & if JPG then .jpg 
    Bitmap scale = new Bitmap(Display.getWidth(),Display.getHeight()); 
    splashImage.scaleInto(scale, Bitmap.FILTER_BILINEAR); 

    VerticalFieldManager mainManager = new VerticalFieldManager(
     VerticalFieldManager.NO_VERTICAL_SCROLL 
       | VerticalFieldManager.USE_ALL_HEIGHT 
       | VerticalFieldManager.USE_ALL_WIDTH) { 
     public void paint(Graphics g) { 
      g.drawBitmap(0, 0, scale.getWidth(), scale.getHeight(), scale, 0, 0); 
      super.paint(g); 
     } 
     }; 
    add(mainManager); 
    //This vertical field can set your converted image as screen background 
    // Note :- you must have to extends FullScreen insteadOf MainScreen