如何在UiApplication上显示图像?
我有一个显示按钮的代码,点击后会转到MainScreen
,但我想在该按钮下面显示一个图像。我找到了一种方法来插入 zoomable 图片,但不是静态图片。
到目前为止,这是我的代码:
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 :(得分: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();
}
}
}