1

ブラックベリーの集計バーを画面に合わせる方法を知りたいです。私のタブはブラックベリー 9700 と一致するためですが、ブラックベリー 9900 ではタブが小さすぎます。私のタブがすべてのデバイス スクリーンに適合するようにします。
前もって感謝します :)

これはコードです。他の投稿から取得しました。ごめんなさい:
BottomPanel クラス

public class BottomPanel extends VerticalFieldManager implements
    FieldChangeListener {

Bitmap home_bit = Bitmap.getBitmapResource("home.png");
Bitmap home_bit_hover = Bitmap.getBitmapResource("home_h.png");
Bitmap map_bit = Bitmap.getBitmapResource("map.png");
Bitmap map_bit_hover = Bitmap.getBitmapResource("map_h.png");
Bitmap contact_bit = Bitmap.getBitmapResource("contact.png");
Bitmap contact_bit_hover = Bitmap.getBitmapResource("contact_h.png");
PictureBackgroundButtonField home_pic, map_pic, contact_pic;

HorizontalFieldManager hr;
int current_index = 0;

public BottomPanel(int current_index) {
    super(FOCUSABLE);
    this.current_index = current_index;
    VerticalFieldManager ver = new VerticalFieldManager(USE_ALL_WIDTH
            | USE_ALL_HEIGHT) {
        protected void sublayout(int width, int height) {
            super.sublayout(width, home_bit.getHeight());
            setExtent(width, home_bit.getHeight());
        }
    };
    hr = new HorizontalFieldManager(FIELD_HCENTER);
    if (current_index == 1) {
        home_pic = new PictureBackgroundButtonField(home_bit.getWidth(),
                home_bit.getHeight(), Field.NON_FOCUSABLE
                        | Field.FIELD_VCENTER, home_bit_hover,
                home_bit_hover);
    } else {
        home_pic = new PictureBackgroundButtonField(home_bit.getWidth(),
                home_bit.getHeight(),
                Field.FOCUSABLE | Field.FIELD_VCENTER, home_bit,
                home_bit_hover);
    }
    home_pic.setChangeListener(this);
    hr.add(home_pic);

    if (current_index == 2) {
        map_pic = new PictureBackgroundButtonField(map_bit.getWidth(),
                map_bit.getHeight(), Field.NON_FOCUSABLE
                        | Field.FIELD_VCENTER, map_bit_hover, map_bit_hover);
    } else {
        map_pic = new PictureBackgroundButtonField(map_bit.getWidth(),
                map_bit.getHeight(), Field.FOCUSABLE | Field.FIELD_VCENTER,
                map_bit, map_bit_hover);
    }
    map_pic.setChangeListener(this);
    hr.add(map_pic);

    if (current_index == 3) {
        contact_pic = new PictureBackgroundButtonField(
                contact_bit.getWidth(), contact_bit.getHeight(),
                Field.NON_FOCUSABLE | Field.FIELD_VCENTER,
                contact_bit_hover, contact_bit_hover);
    } else {
        contact_pic = new PictureBackgroundButtonField(
                contact_bit.getWidth(), contact_bit.getHeight(),
                Field.FOCUSABLE | Field.FIELD_VCENTER, contact_bit,
                contact_bit_hover);
    }
    contact_pic.setChangeListener(this);
    hr.add(contact_pic);

    ver.add(hr);
    add(ver);
}

public void fieldChanged(Field field, int context) {
    if (field == home_pic) {
        LoadingScreen loadingScreen = new LoadingScreen(1);
        UiApplication.getUiApplication().popScreen(
                UiApplication.getUiApplication().getActiveScreen());
        UiApplication.getUiApplication().pushScreen(loadingScreen);
        loadingScreen.createGUI();
    } else if (field == map_pic) {
        LoadingScreen loadingScreen = new LoadingScreen(2);
        UiApplication.getUiApplication().popScreen(
                UiApplication.getUiApplication().getActiveScreen());
        UiApplication.getUiApplication().pushScreen(loadingScreen);
        loadingScreen.createGUI();
    } else if (field == contact_pic) {
        LoadingScreen loadingScreen = new LoadingScreen(3);
        UiApplication.getUiApplication().popScreen(
                UiApplication.getUiApplication().getActiveScreen());
        UiApplication.getUiApplication().pushScreen(loadingScreen);
        loadingScreen.createGUI();
    }
}


ロード画面クラス

public class LoadingScreen extends MainScreen {
private LabelField text;
private LabelField texthasil;
private VerticalFieldManager manager;

int current_index = 0;
BottomPanel bottomPanel;

public LoadingScreen(int current_index) {

    this.current_index = current_index;
    bottomPanel = new BottomPanel(current_index);
    setStatus(bottomPanel);
}

public void createGUI() {

    manager = new VerticalFieldManager(Manager.VERTICAL_SCROLL
            | Manager.VERTICAL_SCROLLBAR);


    setStatus(bottomPanel);
}


PictureBackgroundButtonField クラス

public class PictureBackgroundButtonField extends Field {
private String _label;
private int _labelHeight;
private int _labelWidth;
private Font _font;

private Bitmap _currentPicture;
private Bitmap _onPicture;
private Bitmap _offPicture;

public PictureBackgroundButtonField(int width, int height, long style,
        Bitmap picture, Bitmap selectedPic) {
    super(style);

    _font = getFont();
    _label = "";
    _labelHeight = height;
    _labelWidth = width;
    _currentPicture = picture;
    _onPicture = selectedPic;
    _offPicture = picture;
}

protected void drawFocus(Graphics graphics, boolean on) {
    // Do nothing
}

public int getPreferredHeight() {
    return _labelHeight;
}

public int getPreferredWidth() {
    return _labelWidth;
}

protected void layout(int width, int height) {
    setExtent(getPreferredWidth(), getPreferredHeight());
}

protected boolean navigationClick(int status, int time) {
    fieldChangeNotify(1);
    return true;
}

protected void onFocus(int direction) {
    _currentPicture = _onPicture;
    invalidate();
}

protected void onUnfocus() {
    _currentPicture = _offPicture;
    invalidate();
}

protected void paint(Graphics graphics) {
    graphics.drawBitmap(0, 0, getPreferredWidth(), getPreferredHeight(),
            _currentPicture, 0, 0);
    graphics.setFont(_font);
    graphics.drawText(
            _label,
            4,
            2,
            (int) (getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK),
            getWidth() - 6);
}
4

1 に答える 1

1

タブバーの背景の種類は表示されません。解決策はそれに少し依存します。常に同じ高さ(ピクセル単位) でだけを変更するタブ バーがあれば、次のようなものを使用できます。

という Manager サブクラスを作成しますTabBarManager。固定の高さで、画面の幅全体に広がります。Field通常のマネージャーと同様に、オブジェクトを追加できます。ボタン フィールドを追加して、ボタン フィールドをクリックすると何かが起こるようにするためのものです。おそらく、選択されているタブに応じて、ボタン フィールドの外観も変更する必要があるでしょう。ただし、この質問がその問題に関するものであるかどうかは明確ではなかったため、そのコードは示しませんでした。このコードが行うことは、全幅の背景を描画するタブ フィールドを追加する Manager を提供することだけです。

これに追加するタブ バー フィールドには、背景が透明なアイコン イメージやラベルが含まれている必要があります。たとえば、タブがマップ ビューの場合、地球の白いシルエット アイコン。透明な背景が背景に透けて見えますTabBarManager

テクニックは、(Photoshop などで) 3 つの画像を描画することです。中央の画像。完全なタブ バー イメージを描画することを考えてみてください。次に、左側の数ピクセルを切り取り、.csv として保存しTabBar-left.pngます。右側の数ピクセルをトリミングして名前を付けて保存しTabBar-right.png、次に中央から数ピクセルを切り取って名前を付けて保存しTabBar-center.pngます。コードの下に画像の例を示します。

   /**
    * A TabBarManager provides a horizontal bar of button fields, that serve as a tab bar 
    * header or footer, used to select between available subviews in a larger Screen.
    */
   private final class TabBarManager extends HorizontalFieldManager {

      private int height;
      private Bitmap left;
      private Bitmap center;
      private Bitmap right;

      public TabBarManager() {
         super(HorizontalFieldManager.NO_VERTICAL_SCROLL);  // tab bar itself doesn't scroll
         left = Bitmap.getBitmapResource("TabBar-left.png");
         right = Bitmap.getBitmapResource("TabBar-right.png");
         center = Bitmap.getBitmapResource("TabBar-center.png");
         height = left.getHeight();
      }

      public void sublayout(int width, int h) {
         super.sublayout(width, height);
         setExtent(width, height);   // restrict height to a fixed value
      }

      public int getPreferredHeight() {
         return height;
      }

      public void paint(Graphics g) {
         // draw the background image for the tab bar with two sides and a center section, 
         //  to account for the fact that different devices have different widths
         int width = Display.getWidth();         
         g.drawBitmap(0, 0, left.getWidth(), height, left, 0, 0);

         // fill in the center by repeating the center image as many times as needed
         int x = left.getWidth();
         int centerWidth = center.getWidth();
         int leftEdgeOfRightBitmap = width - right.getWidth();
         while (x < leftEdgeOfRightBitmap) {
            g.drawBitmap(x, 0, centerWidth, height, center, 0, 0);
            x += centerWidth;
         }

         // draw right side
         g.drawBitmap(leftEdgeOfRightBitmap, 0, right.getWidth(), height, right, 0, 0);

         // use super.paint() to draw the icons/labels on top of our background
         super.paint(g);
      }
   }

左、中央、右の PNG (高さは同じである必要があります。幅は関係ありません):

ここに画像の説明を入力ここに画像の説明を入力ここに画像の説明を入力

使用方法

hr表示するコードでは、変数を my のインスタンスに置き換えることができますTabBarManager。または、TabBarManagerクラスの名前を に変更し、BottomPanel必要なコードを追加することもできます...現在のインデックスやフィールド変更リスナーのコールバックなどです。

制限事項

上記の実装では、タブ バーののみが引き伸ばされます。高さは固定です。完全に伸縮可能なタブ バーの場合、9 つの画像 (左上、中央上部、右上、左、中央、右、左下、中央下、右下) を描画して、 9 パッチ画像を模倣することができます。)。または、このようなものを使用して、BlackBerry 用の 9 パッチの伸縮可能な画像を取得します

参考文献

http://supportforums.blackberry.com/t5/Java-Development/Create-tabbed-view-screens/ta-p/444969

于 2013-02-23T04:47:49.730 に答える