2012-03-18 73 views
0

我想在黑莓屏幕的底部顯示4個可點擊的圖像/圖標,我無法找到任何示例應用程序。請分享一些片段。在屏幕底部添加圖像/圖標

我都試過,但我不能夠在底部顯示此圖像,使之可點擊

package com.samples.backgroundImage; 

import net.rim.device.api.ui.*; 
import net.rim.device.api.ui.component.*; 
import net.rim.device.api.ui.container.*; 
import net.rim.device.api.system.*; 

public class NativeUI extends UiApplication 
{ 
    private Bitmap backgroundBitmap; 
    private Bitmap fieldBitmap; 

    public static void main(String[] args) 
    { 
      NativeUI theApp = new NativeUI(); 
      theApp.enterEventDispatcher(); 
    } 

    public NativeUI() 
    { 
     //The background image. 
     backgroundBitmap = Bitmap.getBitmapResource("cryptodemo_jde.png"); 

     MainScreen mainScreen = new MainScreen(); 

     HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT){ 

      //Override the paint method to draw the background image. 
      public void paint(Graphics graphics) 
      { 
       //Draw the background image and then call paint. 
       graphics.drawBitmap(0, 0, 240, 240, backgroundBitmap, 0, 0); 
       super.paint(graphics); 
      }    

     }; 

     //The LabelField will show up through the transparent image. 
     LabelField labelField = new LabelField("This is a label"); 

     //A bitmap field with a transparent image. 
     //The background image will show up through the transparent BitMapField image. 
     BitmapField bitmapField = new BitmapField(Bitmap.getBitmapResource("pimdemo_jde.png")); 

     //Add the manager to the screen. 
     mainScreen.add(horizontalFieldManager); 
     BasicEditField bef = new BasicEditField("To: ","",50,BasicEditField.FILTER_EMAIL); 
     horizontalFieldManager.add(bef); 
     //Add the fields to the manager. 
     horizontalFieldManager.add(labelField); 
     horizontalFieldManager.add(bitmapField); 

     //Push the screen. 
     pushScreen(mainScreen); 
    } 
} 
+0

檢查這個問題,你的代碼,[黑莓 - 如何佔領與圖像的完成按鈕(http://stackoverflow.com/q/4509519/396949 ),在SO上。 – mrvincenzo 2012-03-18 12:59:27

+0

我想在屏幕下方顯示圖像而不是按鈕 – 2012-03-18 13:01:13

+0

@MrVincenzo任何示例 – 2012-03-18 13:13:27

回答

1

我稍微修改代碼。

首先,添加VerticalFieldManager即佔用所有顯示器的高度並垂直對齊字段。 VFM保存除BitmapField以外的所有字段。然後添加一個HorizontalFieldManager,佔據可用顯示屏高度的其餘部分。最後,BitmapField以FIELD_BOTTOM被添加到HFM,其告知HFM將該字段與經理的底部對齊。

如果您想要在屏幕底部添加更多圖像,只需使用FIELD_BOTTOM樣式將它們實例化並將它們添加到HFM。

請查看answer瞭解更多關於字段對齊的信息。

這裏是上述修改

public NativeUI() { 
    //The background image. 
    backgroundBitmap = Bitmap.getBitmapResource("cryptodemo_jde.png"); 

    MainScreen mainScreen = new MainScreen(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_HORIZONTAL_SCROLL); 

    VerticalFieldManager verticalFieldManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL | 
     Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH) { 

     //Override the paint method to draw the background image. 
     public void paint(Graphics graphics) { 
      //Draw the background image and then call paint. 
      graphics.drawBitmap(0, 0, 240, 240, backgroundBitmap, 0, 0); 
      super.paint(graphics); 
     }    
    }; 

    BasicEditField bef = new BasicEditField("To: ","",50,BasicEditField.FILTER_EMAIL); 

    //The LabelField will show up through the transparent image. 
    LabelField labelField = new LabelField("This is a label"); 

    HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT); 
    //A bitmap field with a transparent image. 
    //The background image will show up through the transparent BitMapField image. 
    BitmapField bitmapField = new BitmapField(Bitmap.getBitmapResource("pimdemo_jde.png"), Field.FIELD_BOTTOM); 
    horizontalFieldManager.add(bitmapField); 

    //Add the fields to the manager. 
    verticalFieldManager.add(bef); 
    verticalFieldManager.add(labelField); 
    verticalFieldManager.add(horizontalFieldManager); 

    //Add the manager to the screen. 
    mainScreen.add(verticalFieldManager); 

    //Push the screen. 
    pushScreen(mainScreen); 
} 
+0

感謝它的一個很好的例子,但如何使圖像可點擊? – 2012-03-18 14:21:44

+0

@sheetal_roswal正如我前面提到的,檢查[黑莓 - 如何佔用一個完整的按鈕與圖像](http://stackoverflow.com/q/4509519/396949)的問題。製作你自己的類,並在問題的[答案](http://stackoverflow.com/a/4509592/396949)中放置'BitmapField'。 – mrvincenzo 2012-03-18 14:32:01

+0

感謝@MrVincenzo – 2012-03-18 14:39:59

1
hey it's very simple, just use **setStaus** method for displaying images/icons at the bottom of the screen in the blackberry... 
for example 

/** 
* Initialize Components 
*/ 
ButtonField btn1 = new ButtonField("Button 1"); 
ButtonField btn2 = new ButtonField("Button 2"); 
ButtonField btn3 = new ButtonField("Button 3"); 

HorizontalFieldManager hfm = new HorizontalFieldManager(); 
hfm.add(btn1); 
hfm.add(btn2); 
hfm.add(btn3); 


/** 
* Add Components to Screen 
*/ 
setStats(hfm); 

the setStatus is MainScreen Class method , you can directly use this method in any class that extends MainScreen. & you can find setStatus method in BB 5.0 & above 5.0 OS. 
for more info checkout this link :- 
http://www.blackberry.com/developers/docs/6.0.0api/index.html