Can someone assist me in understanding Animations in CODENAME ONE?

Viewed 28

I am confused as to how various animation classes are utilized in CN1 to achieve desired visuals. Specifically classes such as "ComponentAnimation", "AnimationObject" & "Motion". I have yet to successfully utilize these classes in any way at all.

'''

Form f = new Form(BoxLayout.y());
        f.getStyle().setBgColor(0x004040);
        Label l1 = new Label("Label");
        Container labelContainer = new Container(BoxLayout.y());
        labelContainer.add(l1);

        ComponentAnimation ca1 = labelContainer.createAnimateHierarchyFade(2000, 0);
        labelContainer.getAnimationManager().addAnimation(ca1); //This is line 20.

'''

'''

java.lang.NullPointerException
    at com.avf.ags.GrowSystem.runApp(GrowSystem.java:20)
    at com.codename1.system.Lifecycle.start(Lifecycle.java:130)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.codename1.impl.javase.Executor$4$1.run(Executor.java:341)
    at com.codename1.ui.Display.executeSerialCall(Display.java:1395)
    at com.codename1.ui.Display.processSerialCalls(Display.java:1379)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:1166)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

'''

I got the concept from this post. But I'm not sure how it works.

1 Answers

These are layout animations and will work only when the form is shown. At this point the form isn't shown so they will fail.

I suggest showing the form first. Using a show listener on the form to detect when it actually finished showing. Then add the components and the animation into the already showing form. This will be more consistent with the effect as you want it to appear after any transition animation. Right?

Related