问题
I have two buttons in a horizontal field manager. one i want to put in left side of the screen and another in right side. How can i put them properly without implementing sub layout, so that it can work for all the device?
回答1:
i think creating your custom manager is best way to layout controls. but i think we can that
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH);
vfm.add(new ButtonField("button2",Field.FIELD_RIGHT));
HorizontalFieldManager hfm = new HorizontalFieldManager();
hfm.add(new ButtonField("button1"));
hfm.add(vfm);
add(hfm);
Edit:
if we are using HFM, it is the responsibility of HFM to align in horizontal.
So
HorizontalFieldManager hfm = new HorizontalFieldManager(FIELD_RIGHT);
hfm.add(new ButtonField("button1"));
above code will place button1 to right. but
HorizontalFieldManager hfm = new HorizontalFieldManager();
hfm.add(new ButtonField("button1",FIELD_RIGHT));
above code will not align button right. So when you are using HFM you need to give horizontal align of field in manager and vertical alignment in field.
When you are using VFM you need to give vertical alignment in manager and horizontal alignment in field.
来源:https://stackoverflow.com/questions/7845438/how-to-put-two-buttons-in-horizontal-field-manager-in-blackberry-for-any-device