0

如何在 UiApplication 上显示图像?

我有一个显示按钮的代码,单击它时会转到 a 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);

   }

}
4

1 回答 1

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();
        }    
    }
}
于 2012-05-14T06:55:48.850 回答