0

ブラックベリーの開発は初めてで、サンプルのブラックベリー アプリケーションに画像を追加したいと考えています。複数のチュートリアルを試しましたが、背景に画像が表示されません

誰でも親切に何が問題なのか教えてもらえますか?

/**
 * This class extends the UiApplication class, providing a graphical user
 * interface.
 */
public class Diverse extends UiApplication {

    private Bitmap backgroundBitmap;
    private Bitmap fieldBitmap;


    public static void main(String[] args) {

        Diverse diverse = new Diverse();
        diverse.enterEventDispatcher();
    }

    /**
     * Creates a new MyApp object
     */
    public Diverse() {
        //The background image.
        backgroundBitmap = Bitmap.getBitmapResource("background.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("field.png"));

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

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

        // Push a screen onto the UI stack for rendering.
        pushScreen(new DiverseScreen());
    }
}

DiverseScreenクラスは

package diverse;

import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class DiverseScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
    public DiverseScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("Diverse");
    }
}
4

1 に答える 1

1

問題は、ある画面の背景画像を設定したにもかかわらず、その画面を表示 したことがないことです。次に、背景画像が設定されていない別の画面を表示しました。

まず、BlackBerry UI フレームワークを理解するのに役立ちます。画面上にオブジェクトの階層を作成できます。最上位にはScreen(またはのサブクラスScreen) があり、その内部には がありScreenManagersその内部には がありFieldsます。ただし、各レベルは何らかのコンテナーに追加する必要があり、最後に、トップレベルをpushScreen()Screenなどで表示する必要があります。

ここの最近の回答で、この階層に関するもう少し説明を参照してください

あなたの状況では、この行を変更する必要があります

    MainScreen mainScreen = new MainScreen();

    DiverseScreen mainScreen = new DiverseScreen();

そして、この行を変更します

    pushScreen(new DiverseScreen());

    pushScreen(mainScreen);

これmainScreenは、背景画像を描画する水平フィールド マネージャーを追加したインスタンスです。

于 2013-05-02T04:37:04.697 に答える