08-25-2012 09:04 AM
Hi there,
I want to set a field to always be at the bottom of the screen without using setStatus() since it is opaque. Most threads I've looked at have a complicated layout on top of wanting a field at the bottom. I have a very flexible layout, right now I just have my fields added to the main manager. Is there a good way to push a field to the bottom of the screen? Or is it only possible by overriding some manager's functions?
Ben
Solved! Go to Solution.
08-25-2012 10:01 AM
This is not trivial.
You need to create a manager and tell it to use all height and not be vertically scrollable. So the dimensions that get passed into its sublayout will give you the full height you have available.
Now you should add two Managers to this Manager. The first one is the one you will add all you Fields too - it will be a standard VFM, so that it is scrolling. The second one will be the stuff you want at the bottom of the screen.
In sublayout you will layout the second Field first, get its height and then set its position so it is at the bottom. This will also give you the area that is available for your scrolling Manager. You will then layout this Manager telling it that it is restrcted to the height you have left. As it is scrolling this will not worry it,
Lastly in sublayout you will setExtent making sure you use the full height you have been given.
For further information:
http://supportforums.blackberry.com/t5/Java-Develo
08-25-2012 11:14 AM - edited 08-25-2012 11:22 AM
Something like this?
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | NO_VERTICAL_SCROLL) {
protected void sublayout(int maxWidth, int maxHeight) {
setPositionChild(Manager2, 0, Display.getHeight()-Manager2.getPreferredHeight())
layoutChild(Manager1, maxWidth, maxHeight-Manager2.getPreferredHeight());
setExtent(maxWidth, maxHeight);
}
};
08-25-2012 11:55 AM
Good attempt! It might work too, I'm not sure.
However
1) I would use a VFM, rather than a HFM as the basis for this.
2) You should not use Display.getHeight() as you do, remember that you have told the Manager you are adding this to, that you want to USE_ALL_HEIGHT and not scroll, so it should pass in, in the variable maxHeight, the actual height you have to play with.
3) I would not rely on Manager2 giving the correct value for getPreferredHeight. Instead do this:
layoutChild(Manager2, maxWidth, maxHeight);
now Manager2.getHeight() will tell you exactly how much space it needs. So use that to position Manager2 and to determine the space left for Manager1 when you layout Manager1.
4) I would setPositionChild Manager1 to 0,0
5) When you specify setExtent, you want to tell it the width you actually need. So ask Manager1 and Manager2 what their widths are (once they have been laid out) - the width you actually need will be the maximum of these two values.
08-25-2012 12:18 PM - edited 08-25-2012 12:22 PM
Hi there! Thanks for those tips, they helped a lot. I have one more problem. With this:
final VerticalFieldManager Manager1 = new VerticalFieldManager();
final VerticalFieldManager Manager2 = new VerticalFieldManager();
Manager1.add(new RichTextField("This is Manager 1"));
Manager2.add(new RichTextField("This is Manager 2"));
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | NO_VERTICAL_SCROLL) {
protected void sublayout(int maxWidth, int maxHeight) {
layoutChild(Manager2, maxWidth, maxHeight);
setPositionChild(Manager2, 0, maxHeight-Manager2.getHeight());
layoutChild(Manager1, maxWidth, maxHeight-Manager2.getHeight());
setPositionChild(Manager1, 0, 0);
if(Date.getWidth() > Manager2.getWidth()) {
setExtent(Manager1.getWidth(), maxHeight);
}
else {
setExtent(Manager2.getWidth(), maxHeight);
}
}
};
vfm.add(Manager1);
vfm.add(Manager2);
add(vfm);
I get an infinitely long screen, but the Managers are placed where they're supposed to be! I think it must be something with the height of Manager1 since I can scroll between the two RichTextFields?
08-25-2012 12:24 PM
Ah yes, silly me.
I presume you are adding this to a MainScreen. Define the MainScreen with
USE_ALL_HEIGHT | NO_VERTICAL_SCROLL.
Actually I am not the expert here, the person you want is the person who wrote this article that I think you should read:
http://supportforums.blackberry.com/t5/Java-Develo
I'm just filling in because I know he is not around!
Anyway, I hope by reviewing that article and changing the MainScreen style, you get it working without the infinitely long screen....
08-25-2012 12:49 PM
It works now! I added super(USE_ALL_HEIGHT | NO_VERTICAL_SCROLL); instead of just super(); to my screen object and it works like a charm.
Thank you for the article,
Ben