减少 BlackBerry HorizontalFieldManager 中 2 个按钮之间的空间
在黑莓中,我创建了一个水平字段管理器,并向其添加了一些小尺寸的按钮,以在屏幕底部显示工具栏。但我的问题是两个按钮之间的空间太大。
我必须减少 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.
您是否尝试过使用自定义管理器,您可以根据您的选择放置内容,如下
创建此类的对象并向其添加项目
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
我不确定我是否完全理解你的问题。但如果您将所有按钮放在
HorizontalFieldManager
中,它们都会尝试放在一行中,现在您可以设置HorizontalFieldManager
的边距以显示在底部或某个 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 yourHorizontalFieldManager
to show at bottom or at certain x y position. and then add thisManager
to yourHFM