黑莓编程上的自动旋转

发布于 2024-12-10 13:14:27 字数 151 浏览 0 评论 0原文

我为 Blackberry Storm 编写代码。当我的应用程序处于水平显示(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?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坚持沉默 2024-12-17 13:14:27

这里有两件事,要么您将锁定屏幕方向,要么您将在应用程序中提供支持。

代码示例:检索屏幕方向

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

代码示例:在 BlackBerry API 应用程序中强制纵向视图

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

如果您想要在方向更改时处理图像和其他图形设置,那么您可以执行以下操作:更改您的代码后。

  1. 在 MainScreen 子类中重写子布局方法。

    受保护的无效子布局(int arg0,int arg1){
    // 做所有的事情
    super.sublayout(arg0, arg1);
    }

  2. 检查方向变化,重新排列 UI。对于此类事情,建议使用相对布局。

希望,这可以帮助你。有关详细信息,请访问 Specifying_display_direction_of_screen

编辑: 覆盖 sublayout()然后编写特定于方向的代码

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 事件锁定,您会出错,现在您会这样做对您的代码进行以下更改。

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);
        }

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

Code sample: Retrieving screen orientation

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 sample: Forcing portrait view in a BlackBerry API application

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

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. Override the sublayout method, in your MainScreen subclass.

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

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

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

Edit: 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);
}

Edit 2:

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);
        }
骄兵必败 2024-12-17 13:14:27

好吧,我之前遇到过这个问题并解决了。解决方案不是“强制黑莓屏幕不旋转”。我以前做过这个,这很烦人。解决这个问题的方法是重写主屏幕的 subLayout 方法以及主屏幕中包含的所有管理器。当发生旋转时总是调用此方法。

您的代码将如下所示:

public void sublayout(int width, int height) {
  changeImage(); // this method will change your image x and y and then draw it again
  super.sublayout(width, height);
}

Well I faced this problem before and solved it. The solution is not to "oblige the blackberry screen not to rotate". I made this before and it is annoying. Well the solution to this is override the subLayout method of the main screen and all the managers included in the main screen. This method is always called when a rotation occurs.

Your code will looks like follows:

public void sublayout(int width, int height) {
  changeImage(); // this method will change your image x and y and then draw it again
  super.sublayout(width, height);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文