首页 文章

如何在codenameone中显示容器中心的两个或多个标签

提问于
浏览
2

我是Codenameone的新手是否有任何选项来对齐标签取决于另一个标签,如对齐底部,顶部,右侧和左侧选项?

如何在父布局的中心对齐多个标签?

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
I am getting outpul like the below image

Here I have attached what I need for my project
This is my requirement

Can anyone please help me How should I do to get my requirement?

2 回答

  • 6

    这会将标签放在容器的绝对中心:

    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();
    

    要将中心调整为略微向左移动,您可以向中心容器添加右边距:

    center.getAllStyles().setPadding(Component.RIGHT, 100);
    
  • 0

    这两种方法还用于将标签置于CN1容器内:

    Container container01 = FlowLayout.encloseCenterMiddle();
    

    Container container02 = new Container(new GridLayout(2,1));
    

    其中GridLayout(2,1)中的数字2表示您对一列的标签数量 .

相关问题