2

我想将屏幕垂直分割 30% 和 70%,如何使用 lwit 实现这一点?我使用/尝试过GridLayout,但它平均分割屏幕。需要一个示例代码。

提前致谢!

4

2 回答 2

2

Both other answers will fail when rotating the screen of a device.

You can take two approaches, use a table layout which supports percentage distribution of layout constraints.

Or create a subclass of Contaienr that overrides the calcPreferredSize method and returns a dimension of 30 or 70 percent appropriately. Then just add both of them to a BoxLayout container and use as desired e.g.:

Container c30 = new Container() {
      public Dimension calcPreferredSize() {
          new Dimension(Display.getInstance().getPreferredHeight(), (int)(Display.getInstance().getPreferredWidth() * 0.7));
      }
};
于 2011-12-01T06:47:34.860 回答
-1

创建一个派生 Container 的类:

public class split extends Container {
    public split(int h)
    {
        super();  // you can set your layout type here
        setPreferredH(h);
    }
}

然后在您的 Form 中添加此类的组件:

public class e extends Form {
    private Container c1, c2;
    private TextField f1,f2;
    public e()
    {
        super("test split");
        c1 = new split(30*getPreferredH()/100);
        c2 = new split(70*getPreferredH()/100);
        f1 = new TextField("ghgjhg");
        f2 = new TextField("jkdhuhg");
        c1.addComponent(f1);
        c2.addComponent(f2);
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        addComponent(c1);
        addComponent(c2);
    }
}

您甚至可以将 a 设置backgroundPainter为拆分类以直观地显示拆分。

于 2011-11-30T12:01:00.543 回答