0

I want to create buttons centered horizontally on background created from bitmap. Right now I have vertical field manager with background:

vertical=new VerticalFieldManager()
    {
        protected void paint(Graphics g) 
        {
            g.drawBitmap(0, 0, Display.getWidth(), Display.getWidth(), scaleBit, 0, 0);
            super.paint(g);
        }
        protected void sublayout(int maxWidth, int maxHeight) 
        {   
            super.sublayout(Display.getWidth(), Display.getWidth());
            setExtent(Display.getWidth(), Display.getWidth());
        }
    };      

but when I add paramethers like FIELD_HCENTER | Field.USE_ALL_WIDTH to vertical field manager constructor nothing happens when I add buttons, so how should it be done?

falsetto
  • 789
  • 2
  • 11
  • 35

1 Answers1

0

If this is on a MainScreen you don't need to add the VerticalFieldManager as the screen will have one as its root anyways. I'm going to answer as though the manager needs to be separate as you have it, but this should work either way.

You don't need to override the paint and sublayout methods of your VerticalFieldManager. You should be able to get what you want with standard methods.

public class MyScreen extends MainScreen
{
    public MyScreen()
    {
         super(NO_HORIZONTAL_SCROLL);
         VerticalFieldManager manager = new VerticalFieldManager(USE_ALL_WIDTH | NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL);
         manager.setBackground(BackgroundFactory.createBitmapBackground(null)); // Your bitmap here instead of null

         add(manager);

         ButtonField button = new ButtonField("Button", FIELD_HCENTER);
         manager.add(button);
    }
}

I think the big issue you might be having is a scrollable parent that causes your manager, or button to be placed in the center of and extremely large scroll area.

Kevin
  • 1,626
  • 16
  • 30