Codename One - 两个代码示例中的setScrollVisible

时间:2018-04-29 10:00:43

标签: codenameone

这个问题与此问题有关:Codename One - container.setScrollVisible(true) in the center of a BorderLayout

在下面的代码示例中,setScrollVisible(true)在用户展开Accordion(占据屏幕高度的更多空间)并进行滚动时正常工作:

    Form hi = new Form("Hi World", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE));
    Container body = new Container(BoxLayout.y());
    for (int i = 0; i < 100; i++) {
        body.add(new Label("Label " + i));
    }
    Accordion accordion = new Accordion();
    accordion.addContent("Tap to expand", body);
    Container center = new Container(BoxLayout.y());
    center.add(accordion);
    center.setScrollableY(true);
    center.setScrollVisible(true);
    center.getAllStyles().setPaddingUnit(Style.UNIT_TYPE_DIPS);
    center.getAllStyles().setPadding(2, 2, 2, 2);
    hi.add(BorderLayout.CENTER, center);
    hi.show();

Example of code 1

但是在另一个代码示例中,当用户展开所有Accordions(占据屏幕高度的更多空间)并进行滚动时,setScrollVisible(true)不起作用:

    Form hi = new Form("Hi World", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE));

    // Warning: you need to set the theme property "ComponentGroupBool" to true
    Button button1 = new Button("Button 1", "ButtonMenuCategories");
    CheckBox button11 = CheckBox.createToggle("Button 1.1");
    CheckBox button12 = CheckBox.createToggle("Button 1.2");
    Button button13 = new Button("Button 1.3", "ButtonMenuCategories");
    CheckBox button131 = CheckBox.createToggle("Button 1.3.1");
    CheckBox button132 = CheckBox.createToggle("Button 1.3.2");
    CheckBox button133 = CheckBox.createToggle("Button 1.3.3");
    CheckBox button14 = CheckBox.createToggle("Button 1.4");
    Button button2 = new Button("Button 2", "ButtonMenuCategories");
    Button button3 = new Button("Button 3", "ButtonMenuCategories");
    Button button4 = new Button("Button 4", "ButtonMenuCategories");
    Button button5 = new Button("Button 5", "ButtonMenuCategories");

    Accordion accordion13 = new Accordion();
    ComponentGroup cmpGroup1 = ComponentGroup.enclose(button131, button132, button133);
    cmpGroup1.setScrollable(false);
    accordion13.addContent(button13, FlowLayout.encloseCenter(cmpGroup1));
    Accordion accordion1 = new Accordion();
    ComponentGroup cmpGroup2 = ComponentGroup.enclose(button11, button12, accordion13, button14);
    cmpGroup2.setScrollable(false);
    accordion1.addContent(button1, FlowLayout.encloseCenter(cmpGroup2));
    Accordion accordion2 = new Accordion();
    accordion2.addContent(button2, new Label("Hello"));
    Accordion accordion3 = new Accordion();
    accordion3.addContent(button3, new Label("Hello"));
    Accordion accordion4 = new Accordion();
    accordion4.addContent(button4, new Label("Hello"));
    Accordion accordion5 = new Accordion();
    accordion5.addContent(button5, new Label("Hello"));

    ComponentGroup cmpGroup = ComponentGroup.enclose(accordion1, accordion2, accordion3, accordion4, accordion5);
    Container menu = FlowLayout.encloseCenter(cmpGroup);
    accordion13.setScrollable(false);
    accordion1.setScrollable(false);
    accordion2.setScrollable(false);
    accordion3.setScrollable(false);
    accordion4.setScrollable(false);
    accordion5.setScrollable(false);
    cmpGroup.setScrollable(false);

    menu.setScrollableY(true);
    menu.setScrollVisible(true);

    hi.add(BorderLayout.CENTER, menu);
    hi.show();

Example of code 2

第二个代码示例有什么问题?

0 个答案:

没有答案