12-30-2011 03:42 PM - last edited on 12-30-2011 03:50 PM
I started adding LabelFields to a horizontalfieldmanager expecting it to exceed the limits of the screen, however all the content stays on the screen. I was expecting it to be like the verticalfieldmanager that automatically enables scrolling when content goes beyond the resolution.
How do I enable scrolling horizontally, but more importantly, have only one field appear on screen?
Maybe even have it so that on touchscreens it locks to a field preventing a user from being in the "middle" of images.
Solved! Go to Solution.
12-30-2011 06:10 PM - last edited on 12-31-2011 05:41 AM
Two things:
First you have to tell the HFM to scroll using its style, bits. here is one that I use:
public MyHFM() {
super(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.HORIZONTAL_SCROLL | HorizontalFieldManager.HORIZONTAL_SCROLLBAR );
// .....
}
Secondly you need to make sure the Fields that you add to it all take up a full screen width. If you are adding LabelFields, for example, then you just need to set the style using
LabelField.USE_ALL_WIDTH
Search the forum for other ways to set the Width of a Field.
Edit: As you will see if you look further down, the idea of setting the width of the labelField using USE_ALL_WIDTH is not correct, so please ignore that. Thanks for the correction arkadyz.
12-30-2011 09:34 PM - last edited on 12-30-2011 09:43 PM
Thanks!
I have three labelfields in the hfm, and I added LabelField.USE_ALL_WIDTH to all of them. However only the first one shows up, when I move to the right it's all blank.
Well, since I'm going to use images, I'm just going to make a custoimagefield.
12-31-2011 12:12 AM
Well, USE_ALL_WIDTH alone is not enough - the first field will take all available width (which is, in case of a horizontally scrolling manager, is Integer.MAX_VALUE >> 1 (= 0x3FFFFFFF)). Not exactly what you want, is it?
You'll have to make sure the fields use only the screen width, not the whole available width. You can achieve this the following way:
LabelField label1 = new LabelField("label text", LabelField.USE_ALL_WIDTH | LabelField.HCENTER) {
protected void layout(int width, int height) {
super.layout(Math.min(width, Display.getWidth(), height);
}
};
Make sure you specify HCENTER, not FIELD_HCENTER (if you want the label text to be centered) - the latter will not work and is totally meaningless in conjuction with USE_ALL_WIDTH.
Good luck!