2012-12-05 48 views
1

我有一個呈現白色圓形矩形的VerticalFieldManager。自定義管理器在添加到BlackBerry的VerticalFieldManager後未正確呈現

這是代碼:

VerticalFieldManager _vfmBackground = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | 
       Manager.NO_VERTICAL_SCROLLBAR | Manager.USE_ALL_WIDTH){ 
      public void paint(Graphics graphics) 
       { 
        graphics.clear(); 
        graphics.setColor(Color.WHITE); 
        graphics.fillRoundRect(10, 10,460, 400, 25,25); 
        super.paint(graphics); 
       } 

       protected void sublayout(int maxWidth, int maxHeight) 
       { 
        int displayWidth = (Display.getWidth()); 
        int displayHeight = (Display.getHeight()); 

        super.sublayout(displayWidth, displayHeight); 
        setExtent(displayWidth, displayHeight); 
       } 

     }; 

然後,我創建了一個名爲BaseHeaderBlueScreen自定義Manager類呈現一個藍色的矩形:

public void paint(Graphics graphics) 
    { 
    graphics.clear(); 
    graphics.setColor(610212); 
    graphics.fillRect(20, 0, Display.getWidth(), Display.getHeight()); 
    super.paint(graphics); 
    } 

    protected void sublayout(int maxWidth, int maxHeight) 
    { 
     int displayWidth = (Display.getWidth()-40); 
     int displayHeight = ((Display.getHeight()/2))-90; 

     super.setExtent(displayWidth, displayHeight); 
    } 

最後,我想補充的是自定義的經理與該VerticalFieldManager白色圓角矩形:

BaseHeaderBlueScreen _vhbs = new BaseHeaderBlueScreen(textTop, textBottom, 0); 
     _vhbs.setPadding(20,30,0,0); 
     _vfmBackground.add(_vhbs); 

這是藍色的rec糾結應該顯示在白色矩形內。

enter image description here

但是,這是多麼當前正在顯示藍色矩形(請注意其左側的灰色空間):

enter image description here

我應該怎麼做才能使藍色矩形完全按照需要(沒有左邊的灰色邊框)?

回答

1

我想你只是不必要地打電話給Graphics.clear()clear()的意思是用當前設置爲背景顏色的任何顏色來填充圖形區域。通常情況下,你可以使用clear()這樣的:

public void paint(Graphics g) { 
    g.setBackgroundColor(Color.GRAY); 
    // calling clear makes the background gray 
    g.clear(); 

    // now draw some text 
    g.setColor(Color.WHITE); 
    g.drawText("hello", 20, 40); 
} 

API docs for clear()

清除整個圖形區域的當前背景色。請注意,在這種情況下不應用全局alpha。

但是,在撥打其他電話之前,您打電話給clear()

所以,僅僅去掉兩個調用clear()(雖然這是造成這一特定問題之一是BaseHeaderBlueScreen.paint()通話)。

+0

謝謝奈特,它的工作! = d – Lucas

相關問題