0

I an trying to implement a screen like below:

enter image description here

For that, I am using following code. It is not working at all.

HorizontalFieldManager outerManager = new HorizontalFieldManager(FIELD_BOTTOM|USE_ALL_HEIGHT);
        outerManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("img/bghome.png")));

final FCLabelField selectedLabel = new FCLabelField("Hello World", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER);

selectedLabel.setFontColor(Color.BLACK);
selectedLabel.setBackground(BackgroundFactory.createSolidBackground(0x00cccccc));
outerManager.add(selectedLabel);

HorizontalFieldManager innerManager = new HorizontalFieldManager();

innerManager.setPadding(0, 10, 0, 10);


innerManager.add(new ButtonField( "Button 1", ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT ));
innerManager.add(new ButtonField( "Button 2", ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT ));
innerManager.add(new ButtonField( "Button 3", ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT ));
innerManager.add(tab4);
innerManager.add(tab5);

outerManager.add(innerManager);

innerManager.setBackground(BackgroundFactory.createSolidBackground(0x00cccccc));

add(outerManager);

What is the problem in my code? How I can set a screen like above?

tonymontana
  • 5,728
  • 4
  • 34
  • 53
dev_android
  • 8,698
  • 22
  • 91
  • 148

2 Answers2

2

Try to add all the buttons in one HorizontalFieldManager, and use setStatus(the hfmInwhich you have added the buttons). This will set the button at the bottom of the screen. And Add the labelField Hello world before setStatus. Thats it. :)

BBdev
  • 4,898
  • 2
  • 31
  • 45
  • How to set the background image? – dev_android Mar 22 '12 at 11:31
  • `setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource(your image path)))`; try to call this on manager. – BBdev Mar 22 '12 at 11:33
  • and you want to set the background so just make a hfm give it the required height and use the above code on that manager and add that before your setStatus(); – BBdev Mar 22 '12 at 11:35
  • Are you telling me to set the hfm to FIELD_BOTTOM|USE_ALL_HEIGHT and add another hrm in it, all the buttons will be added in the inner hrm? – dev_android Mar 22 '12 at 12:02
2

There are several ways to achieve what you asked. One way is to use the setStatus() method as BBdev suggested (it will work only for screens of type MainScreen and won't work for screens of type FullScreen). Another alternative would be to do the alignment to bottom manually.

Important alignment rules to remember:

  • A HorizontalFieldManager can only align fields vertically. When adding fields to horizontal manager, only these alignment styles have effect: FIELD_TOP, FIELD_VCENTER, FIELD_BOTTOM.

  • A VerticalFieldManager can only align fields horizontally. When adding fields to vertical field manager, only these alignment styles have effect: FIELD_LEFT, FIELD_HCENTER, FIELD_RIGHT.

Here is a code snippet that does what you asked.

public class UISandbox extends MainScreen {
    public UISandbox() {
        super(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL | USE_ALL_HEIGHT | USE_ALL_WIDTH);

        HorizontalFieldManager outerManager = new HorizontalFieldManager(USE_ALL_HEIGHT);
        outerManager.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("img/bghome.png")));

        VerticalFieldManager innerMngr = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_BOTTOM); 
        final LabelField selectedLabel = new LabelField("Hello World", FIELD_HCENTER) {
            protected void paint(Graphics g) {
                g.setColor(Color.BLACK);
                super.paint(g);
            }
        };
        selectedLabel.setBackground(BackgroundFactory.createSolidBackground(0x00cccccc));
        innerMngr.add(selectedLabel);

        GridFieldManager innerInnerMngr = new GridFieldManager(1, 3, USE_ALL_WIDTH);
        innerInnerMngr.setPadding(10, 0, 10, 0);
        innerInnerMngr.setColumnProperty(0, GridFieldManager.AUTO_SIZE, 0);
        innerInnerMngr.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
        innerInnerMngr.setColumnProperty(2, GridFieldManager.AUTO_SIZE, 0);
        innerInnerMngr.add(new ButtonField("Button 1", ButtonField.CONSUME_CLICK | FIELD_HCENTER));
        innerInnerMngr.add(new ButtonField("Button 2", ButtonField.CONSUME_CLICK | FIELD_HCENTER));
        innerInnerMngr.add(new ButtonField("Button 3", ButtonField.CONSUME_CLICK | FIELD_HCENTER));

        innerMngr.add(innerInnerMngr);
        outerManager.add(innerMngr);
        add(outerManager);
    }
}
tonymontana
  • 5,728
  • 4
  • 34
  • 53