【问题标题】:Bg image issue - cn1背景图片问题 - cn1
【发布时间】:2017-01-03 13:03:41
【问题描述】:

我被困在一个简单的动画代码中,它没有。容器中的组件从屏幕顶部移动到特定位置。我在包含所有组件的容器中的 UIID“AttempTitle”中设置了一个 bg 图像。问题是当所有组件都从顶部移动时,直到它到达特定位置并最终出现时才看到 bg img。如何使背景图像与组件一起移动。

我在执行此操作时遇到了另一个问题。我在标题容器中有一个 bg 图像。在动画发生时,标题容器的绿色背景图像也会消失一秒钟。这是怎么回事,我想不通。

我在 youtube 上上传了一个视频,如果您不了解问题,请查看它。

https://youtu.be/6Or26wxnzUY

代码:

setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER));

attemptIcon = theme.getImage("attemptIcon.png");
attempt1 = new Label(attemptIcon);
attempt2 = new Label(attemptIcon);
attempt3 = new Label(attemptIcon);
attempt4 = new Label(attemptIcon);
attempt5 = new Label(attemptIcon);

attemptContainer = BoxLayout.encloseX(attempt1, attempt2, attempt3, attempt4, attempt5);

Container titleContainer = new Container(new GridLayout(1));
titleContainer.add(FlowLayout.encloseCenterMiddle(attemptContainer));
add(BorderLayout.NORTH, titleContainer);

attemptContainer.getParent().setUIID("AttempTitle");
attemptContainer.getParent().setPreferredW(screenWidth / 3);

questionAnswerContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));

Label a = new Label("questin answer");
questionAnswerContainer.add(a);

titleDialog = new Label("Yuppie!");
body1 = new Label("Let’s celebrate");
body2 = new Label("with another");
body3 = new Label("drink");
Button ok = new Button(theme.getImage("playIcon.png"));
ok.addActionListener(e -> {
    new Test(sm).show();
});

dialogContainer = (BoxLayout.encloseY(titleDialog, body1, body2, body3, ok));
dialogContainer.getAllStyles().setBgImage(theme.getImage("yuppieDialog.png"));

add(BorderLayout.CENTER, LayeredLayout.encloseIn(questionAnswerContainer, FlowLayout.encloseCenterMiddle(dialogContainer)));
titleDialog.getAllStyles().setMarginTop((dialogContainer.getPreferredW() / 3) + 30);

dialogContainer.getParent().setVisible(false);//using setHidden(true) gives same issue

Runnable r = new Runnable() {
    public void run() {
        checkIfCorrect(Test.this);
    }
};
if (timer == null) {
    timer = new UITimer(r);
}
if (timer != null) {
    timer.schedule(5000, false, Test.this); //4 seconds
}
revalidate();

checkIfCorrect 方法:

public void checkIfCorrect(Form f) {
    dialogContainer.getParent().setY(-Display.getInstance().getDisplayHeight());
    dialogContainer.getParent().setVisible(true);
    f.animateHierarchyAndWait(1200);
    f.setTransitionInAnimator(null);
}

工具栏代码:

Toolbar toolbar = new Toolbar();
form.setToolbar(toolbar);
Container containerTitle = new Container(new BorderLayout());
toolbar.setTitleComponent(LayeredLayout.encloseIn(containerTitle, FlowLayout.encloseCenter(ruslanLogo)))
//there r 4 buttons inside containerTitle container

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    您应该使用animateLayout 而不是animateHierarchy 首先将您想要的元素设置为可见 false 然后显示。然后将其 Y 设置为正确的位置,将其设置为可见并进行动画布局。

    问题是Container 的背景大小/位置由于动画而无法正常工作。

    【讨论】:

    • 在代码中将 animateHierarchy 替换为上面的 animateLayout 没有任何作用,根本没有动画效果。组件刚刚出现。
    • 确保在正确的容器上执行此操作。不在内容窗格或右子窗体上。
    • thankyou shai 我制作了一个容器(添加到主窗体边框布局中心)并将所有组件保留在其中,然后为该容器设置动画并且它工作。但是组件从工具栏下方向下滑动。如何使它在工具栏上方动画?我也上传了上面的工具栏代码。
    • 工具栏上方有点复杂,因为工具栏实际上位于不同的层中。尝试使用分层工具栏,甚至根本不使用工具栏,只在北方放置元素。
    猜你喜欢
    • 2016-06-25
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多