2011-11-30 70 views
2

我想垂直分割屏幕30%和70%,我怎樣才能達到這與lwuit?我使用/嘗試GridLayout,但它平分屏幕。需要一個示例代碼。按比例分割屏幕LWUIT

在此先感謝!

回答

2

旋轉設備的屏幕時,其他答案都會失敗。

您可以採取兩種方法,使用支持佈局約束的百分比分佈的表格佈局。

或者創建一個覆蓋calcPreferredSize方法的Contaienr的子類,並適當返回30或70%的維數。然後,只需將它們兩個都加入到BoxLayout容器中並按需要使用,例如:

Container c30 = new Container() { 
     public Dimension calcPreferredSize() { 
      new Dimension(Display.getInstance().getPreferredHeight(), (int)(Display.getInstance().getPreferredWidth() * 0.7)); 
     } 
}; 
-1

創建其派生的容器類:

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的分班直觀地顯示出分裂。