Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

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. :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top