手风琴不能顺利运作

时间:2017-09-06 10:09:24

标签: codenameone

我已经尝试过手风琴,它在模拟器和设备中都没有顺利扩展和收缩。它会突然扩展和收缩。

请查看视频here

怎么会有2个滚动条。(在视频的最后你会看到2个滚动条,内部​​滚动条会滚动,最外面会保持静止)最右边的屏幕上会出现一条额外的黑线。

public final class LabourCategory extends Form {

    public LabourCategory(Resources res) {
        super(new BoxLayout(BoxLayout.Y_AXIS));
        setTitle("Labour Category");

        loadComponent(res);
        revalidate();
    }

    public void loadComponent(Resources res) {
        Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        mainContainer.setUIID("small");
        mainContainer.getAllStyles().setBgColor(0xcccccc);
        mainContainer.getAllStyles().setBgTransparency(255);
        mainContainer.getAllStyles().setMarginLeft(3);
        add(mainContainer);

        for (int i = 0; i < 10; i++) {
            Accordion labourCategory = new Accordion();
            labourCategory.addContent("Labour Category " + i,BoxLayout.encloseY(new Label("aaa"),new Label("bbb"), new Label("ccc")));
            labourCategory.setUIID("small");
            labourCategory.getAllStyles().setBgColor(0xffffff);
            labourCategory.getAllStyles().setBgTransparency(255);

            mainContainer.add(labourCategory);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

要解决大胆的动画,请将表单布局更改为BorderLayout并直接将Accordion添加到其中,或将mainContainer更改为BorderLayout

对于Scrollbar,您必须手动将其删除,因为AccordionContainer的子类。

最后,为此目的,您不需要多个Accordion,只需继续向其添加内容。

public final class LabourCategory extends Form {

    public LabourCategory(Resources res) {
        super(new BorderLayout());
        setTitle("Labour Category");

        loadComponent(res);
        revalidate();
    }

    public void loadComponent(Resources res) {
        Accordion labourCategory = new Accordion();
        labourCategory.setUIID("small");
        labourCategory.getAllStyles().setBgColor(0xffffff);
        labourCategory.getAllStyles().setBgTransparency(255);
        labourCategory.setScrollVisible(false); //removes scrollbar

        for (int i = 0; i < 10; i++) {
            labourCategory.addContent("Labour Category " + i, BoxLayout.encloseY(new Label("aaa"), new Label("bbb"), new Label("ccc")));
        }

        Container mainContainer = BorderLayout.center(labourCategory);
        mainContainer.setUIID("small");
        mainContainer.getAllStyles().setBgColor(0xcccccc);
        mainContainer.getAllStyles().setBgTransparency(255);
        mainContainer.getAllStyles().setMarginLeft(3);

        add(CENTER, mainContainer);    
    }

}