如何在代号名称中使用Tabs时如何修复容器大小?

时间:2016-01-29 06:36:45

标签: java tabs codenameone

我正在使用Tabs Class并构建三个选项卡,我已经添加了带有Grid Layout的容器,并且在该容器中我添加了一些按钮。我的问题是当我在标签之间导航时,容器的大小会自动增加。如何将容器大小设置为默认屏幕大小?

这是代码

Tabs tabs = new Tabs();
    tabs.setChangeTabContainerStyleOnFocus(true);
    tabs.setSwipeActivated(true);
    tabs.setTabTextPosition(RIGHT);
    tabs.setChangeTabContainerStyleOnFocus(true);
    Container notContainer = new Container(new BorderLayout());
    Label tab2a = new Label("Mahesh");
    Label tab2b = new Label("Narkar");
    notContainer.addComponent(BorderLayout.NORTH, tab2a);
    notContainer.addComponent(BorderLayout.CENTER, tab2b);
    Container preContainer = new Container(new GridLayout(4,1));
    Button templateBtn = new Button("Template");
    Button createPreBtn = new Button("Create/Review Prescription");
    Button complianceBtn = new Button("Compliance");
    preContainer.addComponent(templateBtn);
    preContainer.addComponent(createPreBtn);
    preContainer.addComponent(complianceBtn);
    Container youContainer = new Container(new GridLayout(7, 1));
    Button profileBtn = new Button("Profile");
    Button statementBtn = new Button("Statement");
    Button viewApptBtn = new Button("View Appointment");
    Button referBtn = new Button("Refer");
    Button helpBtn = new Button("Help");
    Button settingBtn = new Button("Setting");
    Button contactBtn = new Button("Contact");
    youContainer.addComponent(profileBtn);
    youContainer.addComponent(statementBtn);
    youContainer.addComponent(viewApptBtn);
    youContainer.addComponent(referBtn);
    youContainer.addComponent(helpBtn);
    youContainer.addComponent(settingBtn);
    youContainer.addComponent(contactBtn);

    tabs.addTab("NOTIFICATION", MainForm.getResources().getImage("notification_icon.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()), notContainer);
    tabs.addTab("PRESCRIPTION", MainForm.getResources().getImage("notification_icon.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()), preContainer);
    tabs.addTab("YOU", MainForm.getResources().getImage("notification_icon.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()), youContainer);
    tabs.setTabSelectedIcon(0, MainForm.getResources().getImage("white_background.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()));
    tabs.setTabSelectedIcon(1, MainForm.getResources().getImage("white_background.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()));
    tabs.setTabSelectedIcon(2, MainForm.getResources().getImage("white_background.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()));
    addComponent(tabs);

当我在标签之间导航时,结果是输出 这是输出屏幕截图......

enter image description here enter image description here

1 个答案:

答案 0 :(得分:1)

问题是你正在使用的gridLayout。为保持一致性,请更改此行:

Container youContainer = new Container(new GridLayout(7, 1));

为:

Container youContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
youContainer.setScrollableY(true);

但如果您的要求需要使用GridLayout,请将表单布局设置为BorderLayout并将Tab添加到中心:

setLayout(new BorderLayout());
addComponent(BorderLayout.CENTER, tabs);

然后将您的youContainer包装在BoderLayout中:

tabs.addTab("YOU", MainForm.getResources().getImage("notification_icon.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()), BorderLayout.center(youContainer));