我向Blackberry Storm编写代码。当我的应用程序水平显示(480x360)时,它可以工作。但是,当黑莓手机倾斜到“垂直”(360x480)时,图片将被切断。所以我问如何设置以便在旋转时也调整图片大小?有什么方法可以检查BlackBerry是否再次水平或垂直显示?

谢谢。

最佳答案

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

代码示例:检索屏幕方向

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应用程序中强制肖像 View
// Use code like this before invoking UiApplication.pushScreen()
int direction = Display.DIRECTION_NORTH;
Ui.getUiEngineInstance().setAcceptableDirections(direction);

您要在方向更改时处理图像和其他图形设置,则可以在代码中进行以下更改。
  • 覆盖MainScreen子类中的sublayout方法。

    protected void sublayout(int arg0,int arg1){
    //完成所有
    super.sublayout(arg0,arg1);
  • 检查方向更改,重新排列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);
            }
    

    关于blackberry - 在Blackberry编程上自动旋转,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7789734/

    10-13 09:46