减少 BlackBerry Horizo​​ntalFieldManager 中 2 个按钮之间的空间

发布于 2024-10-08 20:45:09 字数 1211 浏览 0 评论 0原文

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

我必须减少 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)

In Blackberry I have created a horizontal field manager and added some buttons of small size to it to display toolbar at the bottom of the screen. But my problem is there is too much space between the 2 buttons.

I have to reduce this space between 2 buttons so that I can manage to place at least 6 buttons at the bottom of the screen. I am using the BFmsg.setMargin(305,0,0,40) statement.

Following is my code :

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔戏命师 2024-10-15 20:45:09

setMargin(305,0,0,40) // = TOP, RIGHT, BOTTOM, LEFT

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

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

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

setMargin(305,0,0,40) // = TOP, RIGHT, BOTTOM, LEFT

The margin is relative to the nearest object of the value specified.

So simply reducing the left value from 40 to something smaller should allow you to fit more objects in the horizontal field.

Possibly you will want to take the (Display.getWidth() - (button.getWidth()*numButtons))/numButtons+1 to calculate even left margin spacing.

何以笙箫默 2024-10-15 20:45:09

您是否尝试过使用自定义管理器,您可以根据您的选择放置内容,如下

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

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);
         }
     }

have u tried using custom manager u can place the contents as per ur choice like this

Create object of this class and add items to it

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);
         }
     }
难以启齿的温柔 2024-10-15 20:45:09

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

I am not sure if i understand your question fully. but if you place all your buttons in HorizontalFieldManager they will all try to fit in one row now you can set margin for your HorizontalFieldManager to show at bottom or at certain x y position. and then add this Manager to your HFM

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文