Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Regular Contributor
geestring
Posts: 68
Registered: 12-19-2011
My Carrier: Virgin Mobile
Accepted Solution

HorizontalFieldManager horizontally scroll to create image gallery

[ Edited ]

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.

 

 

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: HorizontalFieldManager horizontally scroll to create image gallery

[ Edited ]

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. 

Please use plain text.
Regular Contributor
geestring
Posts: 68
Registered: 12-19-2011
My Carrier: Virgin Mobile

Re: HorizontalFieldManager horizontally scroll to create image gallery

[ Edited ]

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.

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: HorizontalFieldManager horizontally scroll to create image gallery

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!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.