Skip to content

Instantly share code, notes, and snippets.

@codenameone
Last active July 8, 2020 09:57
Show Gist options
  • Save codenameone/ba6fdc5f841b083e13e9 to your computer and use it in GitHub Desktop.
Save codenameone/ba6fdc5f841b083e13e9 to your computer and use it in GitHub Desktop.
Demonstrates the unlayout API in Codename One layout animations
Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));
Button fall = new Button("Fall");
fall.addActionListener((e) -> {
if(hi.getContentPane().getComponentCount() == 1) {
fall.setText("Rise");
for(int iter = 0 ; iter < 10 ; iter++) {
Label b = new Label ("Label " + iter);
b.setWidth(fall.getWidth());
b.setHeight(fall.getHeight());
b.setY(-fall.getHeight());
hi.add(b);
}
hi.getContentPane().animateLayout(20000);
} else {
fall.setText("Fall");
for(int iter = 1 ; iter < hi.getContentPane().getComponentCount() ; iter++) {
Component c = hi.getContentPane().getComponentAt(iter);
c.setY(-fall.getHeight());
}
hi.getContentPane().animateUnlayoutAndWait(20000, 255);
hi.removeAll();
hi.add(fall);
hi.revalidate();
// the following lines demonstrate the async version of the last few lines above
/*hi.getContentPane().animateUnlayout(20000, 255, () -> {
hi.removeAll();
hi.add(fall);
hi.revalidate();
});*/
}
});
hi.add(fall);
@codenameone
Copy link
Author

Sample usage code for animateUnlayout

From the Codename One project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment