Codename One - how to use onTitleScrollAnimation with BorderLayout?

1

as the Toolbar or Titlearea on scroll animation feature is referenced in the last section of the Toolbar API, and also in this great video tutorial (starting at about min 45), the animation works well under given circumstances.

I was not able to find any documentation about what these have to be, however I found one circumstance, in which it does not work. Here is a working example to demonstrate the problem:

        Form hi = new Form("Title", new BoxLayout(BoxLayout.Y_AXIS));
        EncodedImage placeholder = EncodedImage
                .createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
        URLImage background = URLImage.createToStorage(placeholder, "400px-AGameOfThrones.jpg",
                "http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg");
        background.fetch();
        Style stitle = hi.getToolbar().getTitleComponent().getUnselectedStyle();
        stitle.setBgImage(background);
        stitle.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
        stitle.setPaddingUnit(Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS);
        stitle.setPaddingTop(15);

//      hi.setLayout(new BorderLayout()); // uncomment this for the animation to break
        Container contentContainer = new Container(BoxLayout.y());
        contentContainer.setScrollableY(true);
        // add some elements so we have something to scroll
        for (int i = 0; i < 50; i++)
            contentContainer.add(new Label("Entry " + i));
        hi.add(contentContainer);
//      hi.add(BorderLayout.CENTER, contentContainer); // use this line instead of the above for the animation to break

        ComponentAnimation anim = hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200);
        hi.getAnimationManager().onTitleScrollAnimation(anim);
        hi.show();

With my current app and the codesample from the Toolbar API (which is roughly adapted here), I found out that the onScrollAnimation event is not being called, when a scroll occurs inside a BorderLayout. Even when I have a separate container, which is not the contentpane itself, and I set setScrollableY(true); to true, the animation works properly. The animation stops working, when this very container is put into Center of the Form, via Borderlayout. in the example above, the layout is exactly the same, as there are no other components in other areas of course, but it breaks the animation.

How to solve this? In my app, I have the need for a BorderLayout but still want to use this cool feature. Also, this is a very un-intuitive feature, if it works for some, but not all layouts. It should be completely layout-agnostic and work in every case.

Thank you.

animation
codenameone
asked on Stack Overflow Aug 9, 2019 by Lequi

2 Answers

0

The adapter is bound to the forms content pane scrolling so it won't work if you have a border layout in here. In that case scrolling isn't detected because the code just isn't aware of the scrolling. It would need to track the scrolling of any component in the UI to detect that scrolling.

answered on Stack Overflow Aug 10, 2019 by Shai Almog
0

as hinted by Shai, the solution is the following:

    hi.setLayout(new BorderLayout()); 
    Container contentContainer = new Container(BoxLayout.y());
    contentContainer.setScrollableY(true);

    // add some elements so we have something to scroll
    for (int i = 0; i < 50; i++)
        contentContainer.add(new Label("Entry " + i));

    hi.add(BorderLayout.CENTER, contentContainer); // use this line instead of the above for the animation to break

    ComponentAnimation anim = hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200);
    hi.getAnimationManager().onTitleScrollAnimation(contentContainer, anim);

instead of using the onTitleScollAnimation to just add the animation, provide your own scrollable "body" or content container as the first argument, appended by the animation(s).

answered on Stack Overflow Aug 15, 2019 by Lequi

User contributions licensed under CC BY-SA 3.0