2011-10-12 39 views
0

我能夠將背景僅添加到屏幕中添加的字段中,代碼如下: VerticalFieldManager manager = new VerticalFieldManager();如何將圖像設置爲黑莓背景

Bitmap image = Bitmap.getBitmapResource("Penguins.jpg"); 

    Background bg = BackgroundFactory.createBitmapBackground(image); 
    manager.setBackground(bg); 
    manager.add(new LabelField("HEll")); 
    add(manager);</code> 

輸出畫面如下圖所示:enter image description here

將如何得到充滿整個屏幕,在它上面顯示的欄位的圖像。謝謝

回答

1
Bitmap background = Bitmap.getBitmapResource("background.png"); 

VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH) { 
      public void paint(Graphics g) { 
       g.drawBitmap(0, 0, "Device Width", "Device Height", 
           background, 0, 0); 
       super.paint(g); 
      } 
     }; 

vfm.add(new LabelField("HEll")); 
add(vfm); 
+0

謝謝。這是工作。但有沒有什麼辦法可以在不使用現場管理器的情況下設置背景?以及如何鎖定屏幕滾動? – Pramod

+1

如果要鎖定垂直滾動,則使用 VerticalFieldManager vfm = new VerticalFieldManager(NO_VERTICAL_SCROLL); 對於水平 \t \t Horizo​​ntalFieldManager hManager = new Horizo​​ntalFieldManager(NO_HORIZONTAL_SCROLL); –

1

你也可以用這段代碼來設置黑莓中的背景圖片,但是這個工程只有5.0或以上。

Background bg = BackgroundFactory.createBitmapBackground(Bitmap bitmap); 

// OR 

Background bg = BackgroundFactory.createBitmapBackground(Bitmap bitmap, int positionX, int positionY, int repeat); 

this.getMainManager().setBackground(bg); 
+0

嗨@Neel它的工作,但當主屏幕有很多內容..比較背景圖片也滾動它..這次它看起來很blury ...這是什麼解決方案? – Hitarth

+0

哪一個你嘗試過創建背景對象的第一個或第二個選項? –

+0

我使用第一.. – Hitarth