1
我被困在一个简单的动画代码,它有一个没有。容器中的组件从屏幕顶部移动到特定位置。我在包含所有组件的容器中的UIID“AttempTitle”中设置了一个bg图像集。问题是,所有的组件从顶部移动,bg img在到达特定位置并且最终出现时才看到。我如何使bg图像随组件一起移动。Bg图像问题 - cn1
我在做这件事时遇到了另一个问题。我在标题容器中有一个bg图像。当动画发生时,标题容器的绿色bg图像也消失了一秒钟。这是怎么发生的,我无法弄清楚。
我有一个视频在youtube上传incase你不明白问题看看它。
代码:
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
在代码中用animateLayout代替animateHierarchy什么都不做,根本没有动画效果。组件刚刚出现。 – beck
确保你在正确的容器上做到这一点。不在内容窗格或右侧子窗体上。 –
thankyou shai我制作了一个容器(添加到mainform borderlayout中心)并将其中的所有组件都保存在其中,然后为该容器设置动画并使其运行。但组件从工具栏下方滑下。如何使它在工具栏上方生成动画?我上面也上传了我的工具栏代码。 – beck