How to fix alignment for vertical and portrait screen in BlackBerry?

后端 未结 2 631
难免孤独
难免孤独 2021-01-06 22:04

I want to do application which will not change UI even if screen is changed to portrait or landscape direction. How to do that?

相关标签:
2条回答
  • 2021-01-06 22:29

    I have made a static method in one of my library classes:

    public static void disableOrientationChange()
    {
        // force app to use only portrait mode
        int directions = Display.DIRECTION_NORTH;
        UiEngineInstance engineInstance = Ui.getUiEngineInstance();
        if (engineInstance != null)
        {
            engineInstance.setAcceptableDirections(directions);
        }
    }
    

    The trick is that this code only works for screens created after running it. So you must run the code BEFORE you show your first screen.

    I call this method from my Application.main(String args) method, just before the call to enterEventDispatcher().

    public static void main(String[] args)
    {
        MyApp app = new MyApp();
    
        /*
         * BlackBerry OS 5.0.0
         * Disable screen orientation changes
         */
        ScreenUtils.disableOrientationChange();
    
        // enters the event processing loop thread if required
        if (!app.isHandlingEvents())
        {
            app.enterEventDispatcher();
        }
    }
    
    0 讨论(0)
  • 2021-01-06 22:33

    you can use this code to set the orientation to portrait. After that even if the device is held in landscape, the orientation wont change.

    Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
    
    0 讨论(0)
提交回复
热议问题