I'm trying to create a HorizontalFieldManager in blackberry app, I want fields to be left aligned which is HFM's default layout but then I want to display one BitmapField right aligned, setMargin(0, 0, 0, Display.getWidth() - bitmap.getWidth()) works fine until I add other Fields in the manager, any ideas please
That's a bit hacky, normally the children are the ones who define the alignment inside the parent manager..
You create the hfm using all width available:
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_WIDTH);
Then you add the fields (or managers) aligned to left:
hfm.add(new LabelField("Left", Field.FIELD_LEFT));
And then you add the fields that must be aligned right. I'm using labels here, but every class extending Field (including managers) has a constructor accepting flags as argument:
hfm.add(new LabelField("Right", DrawStyle.RIGHT | Field.USE_ALL_WIDTH));
Related
I am trying to create a layout as show in the image attached here:
Here are my screen components,
Screen title field
Button at the center of screen
HorizontalFieldManager containing 3 buttons docked to bottom of screen
Add banner, placed as docked below.
I have completed all of the 1, 2 and 4. I have used setStatus(Field) to place the ad banner. Also, I have customized the HorizontalFieldManager for holding 3 fields justified aligned. Now I don't know how could I place it to the bottom of screen just above the add banner, as I've already used setStatus() for the ad banner. Also, if the virtual keyboard comes up, I want it to cover up the bottom of the screen, rather than push the HorizonalFieldManager and ad banner up.
Dont use setstatus for adding banner stuff instead you can use two horizontal managers at bottom of screen considering Display.getHeight().
I ve done similar kind of screen in my application here is the brief info regarding that.
1) parent Manager (either Vertical/Horizontal) say parentManager
2) Two Horozontal managers with appropriate height and Maximum width (override in sublayout of horizontal managers) and add both these two a verticalfield manager(bottommanager)
3) then here comes tricky part. To the parent Manger override sublayout and add these steps
vfm_screen = new VerticalFieldManager(ScrollView.NO_VERTICAL_SCROLL | HORIZONTAL_SCROLL
| NO_VERTICAL_SCROLL){
protected void sublayout(int maxWidth, int maxHeight) {
setPositionChild(parentManager, 0, 0);
layoutChild(parentManager, Display.getWidth(), Display.getHeight());
setPositionChild(bottommanager, 0, Display.getHeight()-114);
layoutChild(bottommanager, Display.getWidth(), 114);
setExtent(Display.getWidth(), Display.getHeight());
};
};
vfm_screen.add(parentManager);
vfm_screen.add(bottommanager);
add(vfm_screen);
Here 114 is hard sized and you can change it based on your requirement. and adding Button to that parent manger at center of screen.
Combine the ad-banner and the 3 justified fields with a VerticalFieldManager, then pass the combined manager to setStatus().
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?
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.
How do I prevent extra space between two fields:
VerticalFieldManager _fieldManagerMiddle =
new VerticalFieldManager(Manager.VERTICAL_SCROLL);
LabelField field = new LabelField("Title");
CustomFieldList list = new CustomFieldList ();
_fieldManagerMiddle.add(field);
_fieldManagerMiddle.add(list);
To manage the space between two managers you can try negative VerticalFieldManager and HorizontalFieldManager.
Have you tried setting the margin to zero? Margin is just a property on the field, but managers use it to decide the minimum space between two fields during layout.
field.setMargin(0,0,0,0);
list.setMargin(0,0,0,0);
You can create custom manager .
inside the sublayout method you can position the contents as per your requirement and choice
I have multiple ButtonFields in a VerticalFieldManager. By default the width of each button depends on the text it contains.
I would like all the buttons to be of the same width - equal to the width of the widest button.
Take a look at the BlackBerry Developers Knowledge Base:
How to - Implement advanced buttons, fields, and managers
Last Updated: 12 February 2010
Article Number: DB-00796
You are probably looking for the VerticalButtonFieldSet!
Step 1 - Extend the VerticalFieldManager class, and make the constructor take in a bunch of Strings that you want to put end each button.
Step 2 - Find the longest of String out of the Strings passed into the manager.
Step 3 - create the button for the longest string
Step 4 - create all other buttons, and set their width to the same as the 1st (see setExtent)
Step 5 - add the buttons to the manager in the order you want them to appear
FIN
Have you tried using the Field.USE_ALL_WIDTH style flag?
Try ButtonField buttonField = new ButtonField("ButtonText", Field.USE_ALL_WIDTH);
and that should use the full width.
If that doesn't work, try extending ButtonField, overriding layout and calling setExtent(width, height) with the width and height that you want.
I'm trying to develop a stock ticker in JDE 4.3.
I found in a recent post that it is possible for two(2) fields to be aligned both horizontal and vertical: Blackberry Field alignment in a VerticalFieldManager.
My question is: is it possible to align horizontally (3) or more ActiveRichTextFields horizontally maybe even five fields? I already have a function that can auto-smooth scroll a VerticalFieldManager
nevermind.. i was using the wrong manager. HorizontalFieldManager does the the trick.