Search code examples
codenameone

AnimateLayout vs AnimateHierarchy


I don't know the difference between animateLayout and animateHierarchy. Sometimes they both work the same way, other times only one of the two allows to get an animation. Reading the linked javadocs, I couldn't see the difference. Thanks for the clarifications


Solution

  • animateLayout works in a flat hierarchy so it doesn't recurse into the containers below to move them. Hierarchy does recurse. It would seem the latter approach is superior and should always be used but that's just not true.

    For most cases you just want to move your components within a flat hierarchy and treat containers as other components. For this case animateLayout() works great. animateHierarchy() might fail by deciding to move elements within a nested container and causing them to obscure incorrectly instead of just resizing the container.

    In other cases the modified layout might not be flat. E.g. we might have multiple layouts working together in a hierarchy and we made a change to the tree of components. In that case animateLayout() will have no effect but animateHierarchy() can solve it.

    animateHierarchy() is slower and more complex by definition. So you should prefer animateLayout() when applicable.