Codename One - Avoid screen size change on Android on app startup

不想你离开。 提交于 2019-12-08 03:28:20

问题


This issue produce two unwanted effects on Android:

  • one execution of the SizeChangedListener (at app startup) that I don't want;
  • a visible and unwanted resizing of the Form background (with the option Style.BACKGROUND_IMAGE_SCALED_FILL) after the app is just started.

The following code, tested on Samsung Galaxy S8+, produces this log:

12-18 00:49:45.594 D/SizeChangedListener(17264): [EDT] 0:0:0,22 - Initial Screen size: 1080 * 2008 12-18 00:49:45.596 I/System.out(17264): showKeyboard false 12-18 00:49:45.623 D/Codename One(17264): sizechanged: 1080 1945 com.codename1.impl.android.CodenameOneView@10f7aa8 12-18 00:49:45.627 D/libEGL (17264): loaded /vendor/lib64/egl/libGLES_mali.so 12-18 00:49:45.633 I/WebViewFactory(17264): Loading com.google.android.webview version 60.0.3112.107 (code 311210750) 12-18 00:49:45.634 D/SizeChangedListener(17264): [EDT] 0:0:0,61 - SizeChangedListener on "hi Form" invoked... 12-18 00:49:45.635 D/SizeChangedListener(17264): [EDT] 0:0:0,64 - New Screen size: 1080 * 1945

This is the very simple code that I used to replicate this issue:

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new Label("Hi world"));
    Log.p("Initial Screen size: " + hi.getWidth() + " * " + hi.getHeight());
    hi.show();

    hi.addSizeChangedListener(l -> {
        Log.p("SizeChangedListener on \"hi Form\" invoked...");
        Log.p("New Screen size: " + hi.getWidth() + " * " + hi.getHeight());
    });

回答1:


We just relay the size of the view and the events we get from Android. The reason for this is probably related to the status bar which might be hidden on launch and is then added for compatibility.

We have an RFE to enable status bar hiding on Android which might resolve this issue although with Android it might create a similar issue in other devices where the status bar isn't hidden by default...



来源:https://stackoverflow.com/questions/47860932/codename-one-avoid-screen-size-change-on-android-on-app-startup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!