【问题标题】:Re fade animation not working properly codenameone重新淡入淡出动画无法正常工作代号
【发布时间】:2016-06-18 12:51:27
【问题描述】:

淡入淡出动画不起作用。串行调用也不起作用。如果我只添加一个组件来淡化,问题仍然存在。这是关于它在模拟器中的外观的视频。

https://www.youtube.com/watch?v=mMyhUC6m9Vk

public class QuizSplash {

private Form current;
private Resources theme;
Label bb;
Label appleLabel;
Label whiteBgLabel;
Image whiteBg;
Image apple;
int deviceHeight;

public void init(Object context) {
    theme = UIManager.initFirstTheme("/theme");
    deviceHeight = Display.getInstance().getDisplayHeight();
    whiteBg = (Image) theme.getImage("whiteBg.png");
    apple = (Image) theme.getImage("apple.png").scaledWidth(deviceHeight / 5);
}

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    showSplashAnimation();
}

public void showSplashAnimation() {
    Form f = new Form(new LayeredLayout());
    f.setUIID("FormAnimation");
    f.getAllStyles().setBgColor(0x339900);
    f.getAllStyles().setBgTransparency(255);

    whiteBgLabel = new Label(whiteBg.scaledHeight(deviceHeight - 80));
    whiteBgLabel.setUIID("treeLabel");
    whiteBgLabel.getAllStyles().setBgColor(0xffffff);
    f.add(FlowLayout.encloseCenter(whiteBgLabel));
    whiteBgLabel.setVisible(false);

    Container bottomContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
    bottomContainer.setUIID("bottomContainer");
    bottomContainer.getAllStyles().setPadding(Component.LEFT, 40);
    f.add(FlowLayout.encloseBottom(bottomContainer));

    Container appleContainer = new Container(new FlowLayout(Component.CENTER, Component.BOTTOM));
    appleLabel = new Label(apple);
    appleLabel.setUIID("apple");
    appleLabel.getAllStyles().setPadding(0, 0, 0, 0);
    appleLabel.getAllStyles().setMargin(0, 0, 0, 0);
    appleContainer.add(appleLabel);
    bottomContainer.add(appleContainer);
    appleLabel.setVisible(false);

    bb = new Label(apple);
    bb.setVisible(false);
    bottomContainer.add(bb);

    //text container to fade in at last - update added starts.........................
    quizContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    f.add(FlowLayout.encloseIn(quizContainer));

    TextArea question = new TextArea("Here is the question?");
    question.setVisible(false);
    question.setUIID("Label");
    question.setEditable(false);
    question.setGrowByContent(true);
    question.setGrowLimit(3);
    quizContainer.add(question);

    Container ansContainer = new Container(new FlowLayout(Component.CENTER));
    quizContainer.add(ansContainer);
    Label yes = new Label("YES");
    yes.setVisible(false);
    Label no = new Label("No");
    no.setVisible(false);
    ansContainer.add(yes);
    ansContainer.add(no);
    //update added ends.........................

    f.show();

    bb.setX(-bb.getWidth());
    bb.setVisible(true);
    bb.getParent().animateHierarchyAndWait(2500);

    Display.getInstance().callSerially(new Runnable() {

        @Override
        public void run() {
            appleLabel.setVisible(true);
            appleContainer.animateHierarchyFadeAndWait(2000, 0);
            whiteBgLabel.setVisible(true);
            whiteBgLabel.getParent().animateLayoutFadeAndWait(3000, 0);

        //update added starts...............
        question.setVisible(true);
        yes.setVisible(true);
        no.setVisible(true);
        quizContainer.animateLayoutFadeAndWait(2000, 0);
        //update added ends...........
        }
    });

}

public void stop() {
    current = Display.getInstance().getCurrent();
}

public void destroy() {
}

}

更新 1: 以下代码在模拟器中工作,但在真实设备中,苹果组件淡入是好的,其他有同样的问题。

    bb.setX(-bb.getWidth());
    bb.setVisible(true);
    bb.getParent().animateHierarchyAndWait(2500);
    Display.getInstance().callSerially(() -> {

        Display.getInstance().callSerially(() -> {
            appleLabel.setVisible(true);
            appleContainer.animateHierarchyFadeAndWait(2000, 0);

            Display.getInstance().callSerially(() -> {
                whiteBgLabel.setVisible(true);
                whiteBgLabel.getParent().animateLayoutFadeAndWait(2000, 0);

                Display.getInstance().callSerially(() -> {
                    question.setVisible(true);
                    yes.setVisible(true);
                    no.setVisible(true);
                    quizContainer.animateLayoutFadeAndWait(2000, 0);
                });
            });
        });
    });

更新 2: 以下代码不适用于模拟器和设备

    bb.setX(-bb.getWidth());
    bb.setVisible(true);
    bb.getParent().animateHierarchyAndWait(2500);

    Display.getInstance().callSerially(() -> {
        appleLabel.setVisible(true);
            appleContainer.animateHierarchyFadeAndWait(2000, 0);

    });
    Display.getInstance().callSerially(() -> {
        whiteBgLabel.setVisible(true);
        whiteBgLabel.getParent().animateLayoutFadeAndWait(2000, 0);
    });
    Display.getInstance().callSerially(() -> {
        question.setVisible(true);
        yes.setVisible(true);
        no.setVisible(true);
        quizContainer.animateLayoutFadeAndWait(2000, 0);
    });

更新3: 用flushAnimation连续替换调用在模拟器和设备中不起作用

bb.setX(-bb.getWidth());
bb.setVisible(true);
bb.getParent().animateHierarchyAndWait(2500);
Display.getInstance().callSerially(() -> {

    Display.getInstance().callSerially(() -> {
        appleLabel.setVisible(true);
        appleContainer.animateHierarchyFadeAndWait(2000, 0);

        f.getAnimationManager().flushAnimation(() -> {
            whiteBgLabel.setVisible(true);
            whiteBgLabel.getParent().animateLayoutFadeAndWait(2000, 0);
            f.getAnimationManager().flushAnimation(() -> {
                question.setVisible(true);
                yes.setVisible(true);
                no.setVisible(true);
                quizContainer.animateLayoutFadeAndWait(2000, 0);
            });
        });
    });
});

在调用中连续添加刷新动画在设备中不起作用

bb.setX(-bb.getWidth());
bb.setVisible(true);
bb.getParent().animateHierarchyAndWait(2500);
Display.getInstance().callSerially(() -> {

    Display.getInstance().callSerially(() -> {
        appleLabel.setVisible(true);
        appleContainer.animateHierarchyFadeAndWait(2000, 0);

        Display.getInstance().callSerially(() -> {
            f.getAnimationManager().flushAnimation(() -> {
                whiteBgLabel.setVisible(true);
                whiteBgLabel.getParent().animateLayoutFadeAndWait(2000, 0);
                f.getAnimationManager().flushAnimation(() -> {
                    question.setVisible(true);
                    yes.setVisible(true);
                    no.setVisible(true);
                    quizContainer.animateLayoutFadeAndWait(2000, 0);
                });
            });
        });
    });
});

更新 4:

Form f = new Form(new BoxLayout(BoxLayout.Y_AXIS));
Label a = new Label(apple);
Label b = new Label(apple);
Label c = new Label(apple);
Label d = new Label(apple);
a.setVisible(false);
b.setVisible(false);
c.setVisible(false);
d.setVisible(false);
f.add(FlowLayout.encloseCenter(a));
f.add(FlowLayout.encloseCenter(b));
f.add(FlowLayout.encloseCenter(c));
f.add(FlowLayout.encloseCenter(d));

f.show();

a.setVisible(true);
a.getParent().animateLayoutFadeAndWait(2000, 0);

Display.getInstance().callSerially(() -> {
    Display.getInstance().callSerially(() -> {
        b.setVisible(true);
        b.getParent().animateLayoutFadeAndWait(2000, 0);

        f.getAnimationManager().flushAnimation(() -> {
            Display.getInstance().callSerially(() -> {
                c.setVisible(true);
                c.getParent().animateLayoutFadeAndWait(2000, 0);

                Display.getInstance().callSerially(() -> {
                    d.setVisible(true);
                    d.getParent().animateLayoutFadeAndWait(2000, 0);
                });
            });
        });
    });
});

【问题讨论】:

  • 能否将图片附加到问题中以便我运行它?
  • 您有许多未定义的变量,并且可以访问无法编译的图像。请提供编译并解释哪个图像去哪里的代码......例如树...
  • 好的,我也添加了变量和所有代码。它现在应该编译。请查看该问题的视频。对于树标签,之前有一个树图像,由于我发现 gif 很麻烦,我只用白色的 bg 图像而不是树。

标签: codenameone


【解决方案1】:

这对我来说不是很好。我建议将标签本身设置为可见 false 而不仅仅是它们的父容器,因为标签本身触发的重绘可能会通过。

您也可以尝试在显示侦听器中触发动画,而不仅仅是callSerially,这应该让表单有足够的时间出现。

【讨论】:

  • 代码没有编译吗?它确实为我编译。你想让我分享项目本身吗?起初我通过将标签可见性设置为 false 进行测试,但它不起作用,所以我将其父可见性设置为 false 但结果相同。而且我将 callSerially 保留在 show listener 中(不起作用),并且还尝试了 showlistener 没有连续调用但没有好处
  • 它编译了,但我没有看到苹果,只看到一部分闪烁。很多事情都不清楚你做了什么,例如图像的分辨率等,并且由于代码有点冗长,因此很难挖掘。我建议将所有不应该显示的东西设置为可见的错误。在这个测试用例中你有太多的事情同时发生,所以我们俩都很难理解具体的问题。我建议消除所有内容,直到找到最窄的测试用例。
  • 好的,我已经从上面的问题中清除了所有不必要的,并保留了 2 个褪色的标签。如果你没有看到苹果褪色,你可以看到白色背景褪色。他们都有同样的问题(即在褪色前闪烁)。运行 2-3 次,因为有时它们会正常褪色。白色 bg 在苹果标签后面,但它仅在 appleLabel 淡入淡出完成后淡入。 ,所以我使用了分层布局
  • 试试:appleLabel.setVisible(true); appleContainer.animateHierarchyFadeAndWait(2000, 0); Display.getInstance().callSerially(() -> { whiteBgLabel.setVisible(true); whiteBgLabel.getParent().animateLayoutFadeAndWait(3000, 0); });
  • 只需在包装代码之后执行此操作,并将其包装在另一个 callSerially 中。这让 EDT 在调用之间刷新。
猜你喜欢
  • 1970-01-01
  • 2014-06-05
  • 1970-01-01
  • 2012-04-13
  • 1970-01-01
  • 1970-01-01
  • 2016-03-19
  • 2012-03-09
  • 1970-01-01
相关资源
最近更新 更多