你的代碼更改爲以下時,BoxLayout的-X不填充屏幕寬度但可以保持增長。因此,將其更改爲2列的GridLayout。
public void Fair() {
Form hi = new Form(new BoxLayout(BoxLayout.Y_AXIS));
hi.setTitle("Fair");
hi.getToolbar().addCommandToLeftBar("", theme.getImage("BlackBack.png"), (evt) -> {
});
hi.getToolbar().addCommandToRightBar("", theme.getImage("BlackMenu.png"), (evt) -> {
});
Image men = theme.getImage("men.png").scaledWidth(Display.getInstance().getDisplayWidth()/2);
Button menButton = new Button(men);
Image women = theme.getImage("women.png").scaledWidth(Display.getInstance().getDisplayWidth()/2);
Button womenButton = new Button(women);
Container container1 = GridLayout.encloseIn(2, menButton, womenButton);
hi.add(container1);
hi.show();
}
創建原始設計:
public void Fair() {
Form hi = new Form(BoxLayout.y());
hi.setTitle("Fair");
hi.setScrollableY(true);
hi.getToolbar().addCommandToLeftBar("", RES.getImage("BlackBack.png"), (evt) -> {
});
hi.getToolbar().addCommandToRightBar("", RES.getImage("BlackMenu.png"), (evt) -> {
});
Image men = RES.getImage("men.png").scaledWidth(Display.getInstance().getDisplayWidth()/2);
Image women = RES.getImage("women.png").scaledWidth(Display.getInstance().getDisplayWidth()/2);
Image accessories = RES.getImage("accessories.png").scaledWidth(Display.getInstance().getDisplayWidth());
Image brands = RES.getImage("brands.png").scaledWidth(Display.getInstance().getDisplayWidth());
Container containerWomen = LayeredLayout.encloseIn(new Label(women),
FlowLayout.encloseCenterMiddle(BoxLayout.encloseY(new Label("for", "SmallLabelUiid"), new Label("Men", "LargeBoldLabelUiid"))));
Button womenButton = new Button();
womenButton.addActionListener(ev -> {
});
containerWomen.setLeadComponent(womenButton);
Container containerMen = LayeredLayout.encloseIn(new Label(men),
FlowLayout.encloseCenterMiddle(BoxLayout.encloseY(new Label("for", "SmallLabelUiid"), new Label("Women", "LargeBoldLabelUiid"))));
Button menButton = new Button();
menButton.addActionListener(ev -> {
});
containerMen.setLeadComponent(menButton);
Container containerMenAndWomen = GridLayout.encloseIn(2, containerMen, containerWomen);
Container containerAccessories = LayeredLayout.encloseIn(new Label(accessories),
FlowLayout.encloseCenterMiddle(BoxLayout.encloseY(new Label("Accessories", "LargeBoldLabelUiid"))));
Button accessoriesButton = new Button();
accessoriesButton.addActionListener(ev -> {
});
containerAccessories.setLeadComponent(accessoriesButton);
Container containerBrands = LayeredLayout.encloseIn(new Label(brands),
FlowLayout.encloseCenterMiddle(BoxLayout.encloseY(new Label("Brands", "LargeBoldLabelUiid"), new SpanLabel("A man's worth is no greater than his ambitions", "SmallLabelUiid"))));
Button brandsButton = new Button();
brandsButton.addActionListener(ev -> {
});
containerBrands.setLeadComponent(brandsButton);
hi.add(containerMenAndWomen).add(containerAccessories).add(containerBrands);
hi.show();
}
問題是涉及與https://www.codenameone.com – Diamond
感謝名單蘭詹內置的幫助Android應用,但它不是母語android相關:) –