自动旋转的黑莓编程 [英] Auto Rotation on Blackberry Programming

查看:112
本文介绍了自动旋转的黑莓编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做code到黑莓风暴。当我的应用程序在水平显示(小480x360),它的工作。但当黑莓倾斜成纵长(小360x480),画面被切断。所以,我是问如何设置,这样在旋转的时候,也调整了吗?有没有检查是否再次黑莓水平或垂直显示的任何方法?

I make code to Blackberry Storm. When my application in horizontal display (480x360), it's work. But when the Blackberry tilt into Vertical (360x480), the picture is cut off. So I was asking how to set up so that at the time of rotation, also resize the picture? is there any method to check if BlackBerry again horizontal or vertical display?

感谢。

推荐答案

下面是两件事情,要么你会锁定屏幕方向,否则你会在你的应用程序支持。

Here are two things, either you will lock screen orientation or you will support in your application.

code样品:检索屏幕方向

switch(Display.getOrientation()) 
{
   case Display.ORIENTATION_LANDSCAPE:
      Dialog.alert("Screen orientation is landscape"); break;
   case Display.ORIENTATION_PORTRAIT:
      Dialog.alert("Screen orientation is portrait"); break;
   case Display.ORIENTATION_SQUARE:
      Dialog.alert("Screen orientation is square"); break;
   default:
      Dialog.alert("Screen orientation is not known"); break;
}

code样品:强制纵向视图在黑莓API应用程序

// Use code like this before invoking UiApplication.pushScreen()
int direction = Display.DIRECTION_NORTH;
Ui.getUiEngineInstance().setAcceptableDirections(direction);

您要处理的方向变化图像和其他图形安装程序,那么你可以做你的code以下更改。

You you want to handle the images and other graphics setup on orientation change then you can do the following changes in your code.


  1. 重写sublayout方法,在你的MainScreen子类。

  1. Override the sublayout method, in your MainScreen subclass.

保护无效sublayout(INT为arg0,ARG1 INT){
            //做所有的
            super.sublayout(为arg0,ARG1);
        }

protected void sublayout(int arg0, int arg1) { // do all the super.sublayout(arg0, arg1); }

检查是否有方向变化,重新排列UI。相对布局的惯例,建议这样的事情。

Check for the orientation changes, rearrange the UI. Usages of relative layout is recommended for such things.

希望,这可能会帮助你。欲了解更多信息请访问<一个href=\"http://docs.blackberry.com/en/developers/deliverables/11958/Specifying_display_direction_of_screen_647783_11.jsp\">Specifying_display_direction_of_screen

Hope, this might help you out. For more info visit Specifying_display_direction_of_screen

编辑:替换sublayout(),然后写code特定方向

override sublayout() and then write the code specific to orientation

public void sublayout(int width, int height) {
    switch(Display.getOrientation()) 
        {
           case Display.ORIENTATION_LANDSCAPE:
              // write the piece of code for refreshing the screen UI which screen orientation is landscape
              break;
           case Display.ORIENTATION_PORTRAIT:
               // write the piece of code for refreshing the screen UI which screen orientation is portrait
               break;

        }
  super.sublayout(width, height);
}

编辑2:

你要去,因为UI事件锁错了,现在你做以下更改code。

you were going wrong because of UI event lock, now you do the following changes to your code.

public void sublayout(int maxWidth, int maxHeight) {
            int displayWidth = deviceWidth;
            int displayHeight = deviceHeight;

            switch (Display.getOrientation()) {
            case Display.ORIENTATION_LANDSCAPE:
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                        Dialog.alert("Screen orientation is landscape");
                        // here you need to change your uI code as you want to do in for landscape mode
                        // you may need to delete and add the UI comps manually
                        // if the components added to absolute layout then just refresh the screen it will auto adjust with your new screen size 
                    }
                });

                break;
            case Display.ORIENTATION_PORTRAIT:
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                        Dialog.alert("Screen orientation is PORTRAIT:");
                        // here you need to change your uI code as you want to do in for PORTRAIT mode
                        // you may need to delete and add the UI comps manually
                        // if the components added to absolute layout then just refresh the screen it will auto adjust with your new screen size 

                    }
                });
                break;
            }
            super.sublayout(displayWidth, displayHeight);
            setExtent(displayWidth, displayHeight);
        }

这篇关于自动旋转的黑莓编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆