如何在BlackBerry中修复垂直和纵向屏幕的对齐方式?

iWa*_*tch 2 blackberry

我想做即使屏幕改为纵向或横向也不会改变UI的应用程序.怎么做?

Ric*_*ier 8

我在我的一个库类中创建了一个静态方法:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

诀窍是此代码仅适用于运行后创建的屏幕.因此,您必须在显示第一个屏幕之前运行代码.

我在调用Application.main(String args)之前从我的方法调用此方法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();
    }
}
Run Code Online (Sandbox Code Playgroud)