启动屏幕图像大小

时间:2012-01-12 07:21:11

标签: blackberry java-me blackberry-simulator

我正在为我的BlackBerry应用程序创建一个启动画面。现在,图像没有正确放置在我正在测试的所有模拟器中。 启动画面的图像尺寸应该是多少,以便适合所有设备尺寸?

2 个答案:

答案 0 :(得分: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 :(得分:1)

只需拍摄400X400等图片,然后将该图片放入项目的资源文件夹即可。

然后 在启动画面类文件中,您可以使用设备的高度和放大来调整图像大小。宽度。

    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