【问题标题】:Splash screen image size启动画面图像大小
【发布时间】:2012-01-12 07:21:10
【问题描述】:

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

【问题讨论】:

  • 列出您愿意支持的设备,然后列出它们的屏幕尺寸。并创建具有尺寸的图像(所有屏幕宽度的最小宽度,所有屏幕高度的最小高度)。然后你可以将它垂直和水平居中放置。您还可以使用任何图像并在运行时使用Bitmap.scaleInto(params) 调整它们的大小。

标签: blackberry java-me splash-screen blackberry-simulator


【解决方案1】:

主要部分是,创建扩展UiApplicationStartup类。

这是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;
}
}

试试这个你可以得到。

【讨论】:

    【解决方案2】:

    只需拍摄任何像 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 2020-05-04
      • 1970-01-01
      • 2023-03-16
      • 2022-09-27
      相关资源
      最近更新 更多