2012-01-01 85 views
2

如何放置字段的自定義位置座標經理,而無需使用Horizo​​ntalFieldManager或VerticalFieldManager經理,並沒有使用setMargin():自定義位置(兒童)由座標

__________________________________ 
|manager T    T  | 
|   | y1   |  | 
|   |    |  | 
|   V    |  | 
| x1 --------------  |y2 | 
| <---> | field 1  | |  | 
|  |______________| |  | 
|       |  | 
|       V  | 
|  x2  ------------ | 
| <----------> | field 2 | | 
|     |____________| | 
|         | 
|         | 
__________________________________ 

我可以使用代碼類似於:

public static class MyCustomManager extends Manager { 
     public MyCustomManager() { 
      super(); 
     } 
     public void paint(Graphics g) {/**my painting*/super.paint(g);} 
     protected void sublayout(int width, int height) { 
     super.sublayout(PLOT, AUKST); 

     setPositionChild(??,??)  //Something like this? 
     setPosition(??, ??);  // or this? how? 
     setExtent(??, ??); 
     } 

     } 

非常感謝!

+2

是,黑莓可以通過管理者的子字段列表循環做到這一點。使用setPositionChild(child,x,y)來定位子字段。 – Rupak 2012-01-01 04:31:56

回答

6

嘗試這樣:

public Manager getCustomManager() { 
     Manager myCustomManager = new Manager(Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR|Manager.NO_VERTICAL_SCROLL|Manager.NO_VERTICAL_SCROLLBAR) { 
      protected void sublayout(int width, int height) { 
       //Suppose we have to place two fields in our Manager 
       if (getFieldCount() == 2) { 
        int 
        /** width and height values for the two fields */ 
        w1, h1 , w2, h2 , 
        /** position values for the two fields */ 
        x1=5, y1=5, x2=10, y2=20; 

        // Get the first field added to the manager 
        Field f1 = getField(0); 
        h1 = f1.getHeight(); 
        w1 = f1.getWidth(); 
        // set the available width and height for the first field 
        layoutChild(f1, w1, h1); 
        // Set the position of the first field in the manager 
        setPositionChild(f1, x1, y1); 

        // Get the second field added to the manager 
        Field f2 = getField(1); 
        h2 = f2.getHeight(); 
        w2 = f2.getWidth(); 
        // set the available width and height for the second field 
        layoutChild(f2, w2, h2); 
        // Set the position of the second field in the manager 
        setPositionChild(f2, x2, y2); 

        setExtent(width, height); 
       } else { 
        setExtent(0, 0); 
        // or you can do something else in this case... 
       } 
      }; 
     }; 
     return myCustomManager; 
    } 
+0

請檢查這個問題 http://stackoverflow.com/questions/11011042/tooltip-customisation @HeartBeat – Yatin 2012-06-14 08:24:21