0

在 Blackberry 中,我创建了一个水平字段管理器,并在其中添加了一些小按钮以在屏幕底部显示工具栏。但我的问题是两个按钮之间的空间太大。

我必须减少 2 个按钮之间的空间,以便我可以设法在屏幕底部放置至少 6 个按钮。我正在使用该BFmsg.setMargin(305,0,0,40)语句。

以下是我的代码:

BFcontacts = new ButtonField("Cnt")
    { 
      protected void paint(Graphics graphics) 
         {
        //Bitmap contactsbitmap = Bitmap.getBitmapResource("contacts.jpg");
             //graphics.drawBitmap(0, 0, contactsbitmap.getWidth(), contactsbitmap.getHeight(), contactsbitmap, 0, 0);
             graphics.setColor(Color.WHITE);
             graphics.drawText("Cnt",0,0);
         }
    };


    BFcontacts.setMargin(305,0,0,10);//vertical pos,0,0,horizontal pos
    HFM.add(BFcontacts);

    BFmsg = new ButtonField("Msgs")
    { 
      protected void paint(Graphics graphics) 
         {
        //Bitmap msgsbitmap = Bitmap.getBitmapResource("messages.jpg");
             //graphics.drawBitmap(0, 0, msgsbitmap.getWidth(), msgsbitmap.getHeight(), msgsbitmap, 0, 0);
             graphics.setColor(Color.WHITE);
             graphics.drawText("Msgs",0,0);
         }
    };


    BFmsg.setMargin(305,0,0,40);//vertical pos,0,0,horizontal pos : original
    HFM.add(BFmsg);

   add(HFM)
4

3 回答 3

2

setMargin(305,0,0,40) // = 上、右、下、左

边距相对于指定值的最近对象。

因此,只需将左值从 40 减小到更小的值,就可以让您在水平场中容纳更多对象。

可能您需要使用 (Display.getWidth() - (button.getWidth()*numButtons))/numButtons+1 来计算甚至左边距间距。

于 2010-12-24T05:50:19.463 回答
1

您尝试过使用自定义管理器吗?您可以根据自己的选择放置内容,如下所示

创建此类的对象并向其添加项目

class BottomManager extends Manager
     {
         BottomManager()
         {
             super(Manager.NO_VERTICAL_SCROLL);
         }
         protected void sublayout(int width, int height) 
         {
             Field field = getField(0);
             layoutChild(field,Display.getWidth(), Display.getHeight());
             setPositionChild(field,0,0);

             field = getField(1);
             layoutChild(field,Display.getWidth(), Display.getHeight());
             setPositionChild(field,10+getField(0).getWidth(),0);

             field = getField(2);
             layoutChild(field,Display.getWidth(), Display.getHeight());
             setPositionChild(field,10+getField(1).getWidth(),0);

             field = getField(3);
             layoutChild(field,Display.getWidth(), Display.getHeight());
             setPositionChild(field,getField(2).getWidth()+10,0);

             setExtent(Display.getWidth(), 40);
         }
     }
于 2010-12-24T11:45:03.153 回答
0

我不确定我是否完全理解你的问题。但是,如果您将所有按钮HorizontalFieldManager 都放入其中,它们现在都将尝试排成一行,您可以设置边距HorizontalFieldManager以在底部或某个 xy 位置显示。然后将其添加Manager到您的HFM

于 2010-12-22T07:44:26.153 回答