按比例分割屏幕LWUIT
答
旋转设备的屏幕时,其他答案都会失败。
您可以采取两种方法,使用支持布局约束的百分比分布的表格布局。
或者创建一个覆盖calcPreferredSize
方法的Contaienr
的子类,并适当返回30或70%的维数。然后,只需将它们两个都加入到BoxLayout
容器中并按需要使用,例如:
Container c30 = new Container() {
public Dimension calcPreferredSize() {
new Dimension(Display.getInstance().getPreferredHeight(), (int)(Display.getInstance().getPreferredWidth() * 0.7));
}
};
答
创建其派生的容器类:
public class split extends Container {
public split(int h)
{
super(); // you can set your layout type here
setPreferredH(h);
}
}
然后加入这一类的成分在你的表格:
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);
}
}
你甚至可以设置一个backgroundPainter
的分班直观地显示出分裂。