2013-05-09 58 views

回答

0

我猜中間部分只有滾動的,對不對?

你必須有一個Horizo​​ntalFieldManager與HORIZONTAL_SCROLL(中間的那個) 例如HorizontalFieldManager hfm = new HorizontalFieldManager(HORIZONTAL_SCROLL); 在此經理中添加您的自定義字段。

您必須在自定義OuterManager添加HFM。

供您參考,我在這裏張貼自己的代碼...

private class HScroll extends MainScreen{ 
     public HScroll() { 
      super(USE_ALL_WIDTH); 
      OuterManager father = new OuterManager(); 
      LabelField ll = new LabelField("<"); 
      father.add(ll); 
      HorizontalFieldManager hfm = new HorizontalFieldManager(HORIZONTAL_SCROLL); 
      for(int i=0; i<10; i++){ 
       ButtonField btn = new ButtonField(" i " + i); 
       hfm.add(btn); 
      } 
      father.add(hfm); 
      LabelField ll1 = new LabelField(">"); 
      father.add(ll1); 
      add(father); 
     } 

     private class OuterManager extends net.rim.device.api.ui.Manager{ 

      public OuterManager() { 
       super(USE_ALL_WIDTH); 
      } 

      protected void sublayout(int width, int height) { 

       int x = 0; 
       Field ff = getField(0); 
       Field ff2 = getField(2); 
       setPositionChild(ff, x, 0); 
       layoutChild(ff, ff.getPreferredWidth(), ff.getPreferredHeight()); 

       x = x + ff.getPreferredWidth(); 
       Field ff1 = getField(1); 
       setPositionChild(ff1, x , 0); 
       layoutChild(ff1, width - ff.getPreferredWidth() - ff2.getPreferredWidth() , ff1.getPreferredHeight()); 

       x = width - ff2.getPreferredWidth(); 
       setPositionChild(ff2, x, 0); 
       layoutChild(ff2, ff2.getPreferredWidth(), ff2.getPreferredHeight()); 

       setExtent(width, height); 
      } 
     } 
    } 
+0

還有一個選項,以實現這一目標... TableLayoutManager使用http://supportforums.blackberry.com/t5/ Java的開發/創建-A-豐富的UI佈局與 - TableLayoutManager/TA-p/445299 – 2013-05-09 12:29:18

+0

側箭頭(< and >)也許應該是'ButtonField'對象,而不是'LabelFields'。 – Nate 2013-05-09 20:45:11

+0

@以上只是示例代碼。 – 2013-05-10 07:55:14