问题
I am new for Codenameone Is there any option to align a label depends on another label like align bottom, top, right and left option?
How to align many labels at the centre of the parent layout?
Here I have attached the code I tried for:
Container center = new Container(new BorderLayout());
Label des = new Label((String) data.get("title"));
des.setUIID("MultiLine2");
center.addComponent(BorderLayout.NORTH,des);
Label author = new Label((String) data.get("author"));
author.setUIID("MultiLine2");
center.addComponent(BorderLayout.SOUTH,author);
cnt.addComponent(BorderLayout.CENTER, center);
I am getting outpul like the below image
Here I have attached what I need for my project
Can anyone please help me How should I do to get my requirement?
回答1:
This will place the Labels in the absolute center of the container:
Form hi = new Form("Hi World");
hi.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
Container center = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Label line1 = new Label("What are you doing");
Label line2 = new Label("Hello");
center.add(line1);
center.add(line2);
hi.addComponent(BorderLayout.CENTER, center);
hi.show();
To adjust the center to move slightly to the left you can add right padding to the center Container:
center.getAllStyles().setPadding(Component.RIGHT, 100);
回答2:
These two approaches also serve to center labels inside a CN1 container:
Container container01 = FlowLayout.encloseCenterMiddle();
and
Container container02 = new Container(new GridLayout(2,1));
where the number 2 in GridLayout(2,1) refers to the number of labels you have for one column.
来源:https://stackoverflow.com/questions/37430917/how-to-show-two-or-more-label-at-centre-of-the-container-in-codenameone