如何在codenameone中显示容器中心的两个或多个标签
我是新来的Codenameone有没有任何选项来对齐标签取决于另一个标签,如对齐底部、顶部、右侧和左侧选项 如何在父布局的中心对齐多个标签 我在这里附上了我尝试的代码:如何在codenameone中显示容器中心的两个或多个标签,codenameone,Codenameone,我是新来的Codenameone有没有任何选项来对齐标签取决于另一个标签,如对齐底部、顶部、右侧和左侧选项 如何在父布局的中心对齐多个标签 我在这里附上了我尝试的代码: Container center = new Container(new BorderLayout()); Label des = new Label((String) data.get("title")); des.setUIID("MultiLine2"); center.addComponent(
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);
我越来越像下图所示
这里我附上了我的项目所需的内容
有人能帮助我如何满足我的要求吗?这将把标签放在容器的绝对中心:
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();
Container container01 = FlowLayout.encloseCenterMiddle();
要调整中心使其稍微向左移动,可以向中心容器添加右填充:
center.getAllStyles().setPadding(Component.RIGHT, 100);
这两种方法也可用于将标签置于CN1容器内的中心:
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();
Container container01 = FlowLayout.encloseCenterMiddle();
及
其中GridLayout(2,1)中的数字2指的是一列的标签数量 嗨,陈,我面临着类似的问题,所以我尝试了上面的代码它的工作,但在我的情况下,两者都应该在中心。。在您的解决方案中,两者都是垂直的,但它们都是从左侧开始的,但在我的情况下,无论文本大小,它们都应该位于中心。。你能告诉我我错过了什么吗?