2012-05-14 4 views
0

UiApplicationに画像を表示する方法は?BlackBerryでUiApplicationに画像を表示するには?

私はボタンを表示するコードを持っており、クリックするとMainScreenに行きますが、そのボタンの下に画像を表示したいと思います。 ズーム可能イメージを挿入する方法が見つかりましたが、スタティックイメージではありません。

はここで、これまでに私のコードです:

public class HelloWorldDemo extends UiApplication { 
    private MainScreen _screen; 
    private ButtonField _nextScreen; 

    public static void main(String[] args) { 
     HelloWorldDemo instance = new HelloWorldDemo(); 
     instance.enterEventDispatcher(); 
    } 
    public HelloWorldDemo() { 
     EncodedImage myImg = EncodedImage.getEncodedImageResource("k.jpg"); 

     ZoomScreen zoomableImg = new ZoomScreen(myImg); 


     _screen = new MainScreen(); 
     _nextScreen = new ButtonField("Go to Next Screen",ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK); 
     _nextScreen.setChangeListener(new FieldChangeListener() { 
       public void fieldChanged(Field field,int context) { 
        pushScreen(new NextScreen()); 
       } 
      }); 
      _screen.setTitle(new LabelField("Hello World Demo",LabelField.USE_ALL_WIDTH)); 
      _screen.add(new RichTextField("Hello to the BlackBerry World!",Field.NON_FOCUSABLE)); 
      _screen.add(_nextScreen); 
      pushScreen(_screen); 
      pushScreen(zoomableImg); 

    } 

} 
+0

使用 'BitmapField'画像を表示します。 APIリンクはこちら、http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/component/BitmapField.html 'myImg.getBitmap()'は 'BitmapField'の作成に使用できる' Bitmap'を返します。 – Rupak

答えて

0
//I'm confused about your question. But still I'm posting ans here hope it will help you. 
public final class ZoomScreenDemo extends UiApplication 
{ 
    public static void main(final String[] args) 
    { 
     UiApplication app = new ZoomScreenDemo(); 
     app.enterEventDispatcher(); 
    } 


    public ZoomScreenDemo() 
    { 
     pushScreen(new ZoomScreenDemoScreen()); 
    } 


    public final static class ZoomScreenDemoScreen extends MainScreen 
    {  
     private EncodedImage _image; 
     private ButtonField _nextScreen; 

     public ZoomScreenDemoScreen() 
     {   
      setTitle("Zoom Screen Demo");   

      _nextScreen = new ButtonField("Go to next screen ",ButtonField.CONSUME_CLICK); 
      _nextScreen.setChangeListener(new FieldChangeListener() { 

       public void fieldChanged(Field field, int context) { 
        UiApplication.getUiApplication().pushScreen(new DemoZoomScreen(_image)); 
       } 
      }); 

      add(_nextScreen); 
      _image = EncodedImage.getEncodedImageResource("img/building.jpg");   
      BitmapField bitmapField = new BitmapField(_image.getBitmap(), FIELD_HCENTER | FOCUSABLE); 
      add(bitmapField);    
     }  
    }  



    static class DemoZoomScreen extends ZoomScreen 
    {  
     DemoZoomScreen(EncodedImage image) 
     { 
      super(image); 
     } 

     public void zoomedOutNearToFit() 
     {    
      close(); 
     }  
    } 
} 
+0

あなたの助けをありがとう。私は例としてあなたを使用してゼロからコードを書き直しました、そして、それは今働いています... – Marcelo

関連する問題