gpt4 book ai didi

java - 代号一 - 隐藏单个元素的动画删除所有内容

转载 作者:行者123 更新时间:2023-11-30 10:33:05 25 4
gpt4 key购买 nike

我正在学习有关如何在使用代号一创建的移动应用程序中开始制作动画的基本教程。

https://www.codenameone.com/manual/animations.html

虽然我得到了在容器上使用布局动画和取消布局动画来将事物移入和移出位置的概念,但这似乎不适用于取消布局动画。

下面代码的想法是根据某些搜索结果显示或隐藏元素列表(该示例只有普通标签)。单独使用时,就地动画效果很好,如教程中所示。

但是为什么在调用“animateUnlayoutAndWait()”时一切都完全消失了?

Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));

Button button = new Button("Hide");
hi.add(button);

for (int iter = 0; iter < 10; iter++) {
Label b = new Label("Label " + iter);
b.setWidth(button.getWidth());
b.setHeight(button.getHeight());
b.setY(-button.getHeight());
hi.add(b);
}

button.addActionListener((e) -> {

// hide every second label on click
if (button.getText().equals("Hide")) {
button.setText("Show");
for (int iter = 1; iter < hi.getContentPane().getComponentCount(); iter += 2) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setHidden(false);
}
hi.getContentPane().animateUnlayoutAndWait(500, 0);

}
// show stuff again
else {
button.setText("Hide");
for (int iter = 1; iter < hi.getContentPane().getComponentCount(); iter += 2) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setHidden(true);
}
hi.getContentPane().animateLayoutAndWait(500);
}
});

hi.show();

谢谢和最好的问候

最佳答案

我注意到您错误地交换了 setHidden() 值,if 部分应该为真而 else 部分应该为假。此外,从动画中删除 AndWait

Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));

Button button = new Button("Hide");
hi.add(button);

for (int iter = 0; iter < 10; iter++) {
Label b = new Label("Label " + iter);
b.setWidth(button.getWidth());
b.setHeight(button.getHeight());
b.setY(-button.getHeight());
hi.add(b);
}

button.addActionListener((e) -> {

// hide every second label on click
if (button.getText().equals("Hide")) {
button.setText("Show");
for (int iter = 1; iter < hi.getContentPane().getComponentCount(); iter += 2) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setHidden(true); //should be true here
}
hi.getContentPane().animateUnlayout(500, 255, null); //remove AndWait

} // show stuff again
else {
button.setText("Hide");
for (int iter = 1; iter < hi.getContentPane().getComponentCount(); iter += 2) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setHidden(false); //should be false here
}
hi.getContentPane().animateLayout(500); //remove AndWait
}
});

hi.show();

关于java - 代号一 - 隐藏单个元素的动画删除所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42377003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com