Reduce space between 2 buttons in HorizontalFieldManager in BlackBerry
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(), con开发者_运维百科tactsbitmap.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)
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
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);
}
}
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
精彩评论