03-17-2010 10:05 PM
Hi everyone,
I have a HorizontalFieldManager within a VerticalFieldManager. The HorizontalFieldManager contains a BitmapField in one "cell", and a Custom GridFieldManager in another cell.
I'm trying to make it so that the HorizontalFieldManager is vertically centered on the screen, but have been unable to do so. Most of the forum posts say to "create your own manager". I can do that, however I am unsure what the Manager would need to specify in order to vertically center the HorizontalFieldManager.
Can anyone push me in the right direction? Here is what I have so far:
imageOutputField = new BitmapField();
href = new HrefField("Synopsis", 0xffffff, 0x043184, 0x00EF3825);
href.setChangeListener(this);
grid.add(href);
VerticalFieldManager vfm = new VerticalFieldManager(
Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT
| VerticalFieldManager.VERTICAL_SCROLL
| VerticalFieldManager.VERTICAL_SCROLLBAR);
horiz = new HorizontalFieldManager(DrawStyle.VCENTER);
horiz.add(imageOutputField);
horiz.add(grid);
vfm.add(horiz);
synchronized (UiApplication.getEventLock()) {
add(horiz);
}Thanks!
Solved! Go to Solution.
03-18-2010 06:39 AM
drawstyle.VCENTER may be for text positioning, try Field.FIELD_VCENTER
03-21-2010 10:59 AM
Hi Jack,
I tried out your suggestion, and I am still receiving the same response. Does anyone have any other ideas? Thanks!
03-21-2010 10:55 PM
This works for me:
public class TestScreen extends MainScreen {
public TestScreen() {
super(NO_VERTICAL_SCROLL);
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT);
LabelField lf = new LabelField("Sample Text", FIELD_VCENTER);
hfm.add(lf);
add(hfm);
}
}
The key to using FIELD_VCENTER is to make sure that the parent HorizontalFieldManager is the right height. You have to be careful, especially when using USE_ALL_HEIGHT, that it doesn't get bigger than. That's why I turned off vertical scrolling for the screen. (Otherwise the text will end up centered many thousands of pixels below the screen.) As an alternative, you could subclass HorizontalFieldManager and return a preferred height of the screen height (perhaps minus a header).
04-16-2010 10:50 AM - edited 04-16-2010 10:51 AM
Here's another way:
http://supportforums.blackberry.com/t5/Java-Develo
Bikas wrote:
HorizontalFieldManager hfm = new HorizontalFieldManager();
LabelField testLabel1 = new LabelField( "Test Label1");
LabelField testLabel2 = new LabelField( "Test Label2");
hfm.add(testLabel1);
hfm.add(testLabel2);
int leftEmptySpace = (Display.getWidth() - hfm.getPreferredWidth()) / 2;
int topEmptySpace = (Display.getHeight() - hfm.getPreferredHeight()) / 2;
hfm.setMargin(topEmptySpace, 0, 0, leftEmptySpace);
this.add(hfm);
Worked perfectly. In my opinion it is better this way. You create what you want inside a manager, then add the manager and after that do the math (with getPreferredWidth/height) and set the Margins.