Keep Codename One components in invalid positions after app stop/resume

时光怂恿深爱的人放手 提交于 2019-12-08 04:48:42

问题


My question is about keeping components in invalid positions in the layered pane after app stop/resume. I have a nice animation that moves some components in the layered pane and I want that these components remains in their positions until an user interaction with them.

I understood that when the app goes to the background, the stop() method is invoked: that method stores in the current variable the current Form reference. Then, when the app is resumed, the start() method is invoked, in particolar this code:

if (current != null) {
    current.show();
    return;
}

The problem of this approch is that the app is not resumed "exactly" as it was, because the current.show() seems to revalidate the layered pane of the current Form (I don't want a revalidate because I have some components in invalid positions in the layered pane because I use the animateUnlayout).

As a solution, I tried to comment the current.show(); in the start() method, but this approch doesn't work (it works only in the Simulator, but not on real Android and iOS devices, in which the layered pane is still revalidated after an app stop/resume).

Any idea how can I keep every component in its position after an app stop/resume (without repeating the same animation that moved the components in invalid positions)?


回答1:


When we come back from suspend or the device is rotated we need to layout the components into their natural place The only workaround to this is to disable the layout manager entirely by installing a fake one. This would essentially block layout from happening. I'm not sure if there is a valid use case for this, if it's just a visual animation there might be a better approach.

cnt.setLayout(new Layout() {
    @Override
    public void layoutContainer(Container parent) {
    }

    @Override
    public Dimension getPreferredSize(Container parent) {
        return new Dimension(getDisplayWidth(), getDisplayHeight());
    }
});


来源:https://stackoverflow.com/questions/52589182/keep-codename-one-components-in-invalid-positions-after-app-stop-resume

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