应用停止/恢复后将Codename One组件保持在无效位置 [英] Keep Codename One components in invalid positions after app stop/resume

查看:58
本文介绍了应用停止/恢复后将Codename One组件保持在无效位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是在应用停止/恢复后将组件保持在分层窗格中的无效位置。我有一个不错的动画,它可以在分层窗格中移动某些组件,并且我希望这些组件在用户与它们交互之前保持其位置。

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.

我知道当应用程序转到后台,调用 stop()方法:该方法将当前窗体存储在 current 变量中参考。然后,在恢复应用程序时,将调用 start()方法,特别是以下代码:

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;
}

此方法的问题是该应用程序无法完全恢复为这是因为 current.show()似乎正在重新验证当前表单的分层窗格(我不希望 revalidate ,因为我使用 animateUnlayout ),因此在分层窗格中某些组件处于无效位置。

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).

作为解决方案,我尝试在 start()方法中注释 current.show(); ,但是此方法不起作用(仅在模拟器中有效,而在实际的Android和iOS设备上则无效,在这些设备中,应用停止/恢复后仍会重新验证分层窗格)。

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)?

推荐答案

当我们从暂停状态返回或设备旋转时,我们需要将组件布局为int o他们的自然位置唯一的解决方法是,通过安装伪造的布局管理器来完全禁用布局管理器。这本质上将阻止布局的发生。我不确定是否存在有效的用例,如果只是视觉动画,可能会有更好的方法。

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());
    }
});

这篇关于应用停止/恢复后将Codename One组件保持在无效位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆