2011-04-26 20 views
0

我想在一個登錄屏幕的末尾添加一個位圖欄,並在該位圖欄的頂部,我想放置到按鈕(確定並取消)。我怎麼做?我應該添加該欄到某種背景模板創建屏幕模板或添加頁腳?

public class EcraTemplate extends MainScreen { 
    private HorizontalFieldManager hm; 
    private MyLabelField title; 
    private BitmapField logotipo; 

    public EcraTemplate (long style) { 
     super(style); 
     .... 
     logotipo = new BitmapField... 

     title = new LabelField 
     hm = new HorizontalFieldManager(); 
     hm.add(logotipo); 

     //fill screen 
     this.add(hm); 

如何添加該位圖上的按鈕?

回答

1

您可以使用Manager.setBackground()調用來完成此操作。

HorizontalFieldManager hm = new HorizontalFieldManager(); 
Bitmap bmp = Bitmap.getBitmapResource("background.png"); //whatever your background image name is 
hm.setBackground(BackgroundFactory.createBitmapBackground(bmp); 

之後,您可以像正常一樣添加按鈕。如果你發現你的HFM是不正確的尺寸,你可以修改這是

final Bitmap bmp = Bitmap.getBitmapResource("background.png"); 
HorizontalFieldManager hm = new HorizontalFieldManager(){ 
    protected void sublayout(int width, int height) { 
     super.sublayout(width, height); 
     setExtent(Math.min(bmp.getWidth(), width), Math.min(bmp.getHeight(), height)); 
    } 
}; 

hm.setBackground(BackgroundFactory.createBitmapBackground(bmp); 

因此,這將是你的背景圖像的尺寸。

+2

從4.6.0開始,在BB API中提供'Field.setBackground(背景背景)'也很好。這可能很重要,因爲市場上OS 4.5上仍然有很多設備(即Curve 83xx系列)。對於OS 4.5,您必須通過重寫'Field.paint(圖形圖形)'來手動繪製bg圖像。 – 2011-04-26 18:05:32

+0

優秀點。你的目標操作系統肯定會影響你如何完成這個任務。 – jprofitt 2011-04-26 18:56:42