2012-03-18 67 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