Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified
Accepted Solution

BitmapFields aligning to CENTER

Hi all,

 

Please help me following.

 

I created several BitmapFields and put them in HorizontalFieldManager.

But these BitmapFields are always showing left aligned.

I want these fields be centered.

 

How can I do this?

Any examples?

 

Thanks,

DK.

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: BitmapFields aligning to CENTER

How about setting the style bits?

 

        m_bitmapFld = new BitmapField(m_bitmap,DrawStyle.HCENTER);

Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: BitmapFields aligning to CENTER

Thank you RexDoug.

No luck. It makes that other bitmaps disappeared.

 

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: BitmapFields aligning to CENTER

Ooops - I see now you are using the horizontal manager.

 

Why is this? What are you trying to acccomplish?

 

Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: BitmapFields aligning to CENTER

[ Edited ]

Please see the image below.(or go here http://65.98.94.68/mobile/8800.png) I want the images in the middle of the screen.

 

screenshot

Message Edited by duksunkim on 09-15-2008 04:53 PM
Developer
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: BitmapFields aligning to CENTER

Like so many other things, layout parameters aren't terribly clear when it comes to UI components.  First, you figure that a HFM might be assuming that it's *not* contrained by the screen size; they're often provided a value of a million (or something) for their max extent when they're laying out.  Anyway, I don't want to get started on all the UI stuff..

 

What I did (I only do things once and then I reuse my stuff), is to create my own manager by extending HFM.  I did this for a toolbar component which seems a lot like what you're doing.

 

public Toolbar() { super(NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL); // more init stuff... }

 

  You'll want to disable scrolling as the HFM will make your life difficult otherwise; do your own scrolling if you have more components than will fit on the screen.

 

  Then use sublayout to only layout your children (buttons) and set your extent:

 

 

protected void sublayout(int width, int height) { int fieldCount = getFieldCount(); for (int i = 0; i < fieldCount; i++) { Field field = getField(i); layoutChild(field, width, height); maxFieldHeight = Math.max(maxFieldHeight, field.getHeight()); } int extentHeight = maxFieldHeight + VERTICAL_PADDING * 2; setExtent(width, extentHeight); layoutButtonSpacing(); }

 

  "layoutButtonSpacing" simply determines how many buttons will fit on the screen and, based on that, determines the amount of spacing that should go between them.  It stores that value in an instance variable.

 

  Next, you'll need to override "subpaint" to actually paint your component and your buttons.  A simplfied version of mine follows (removed background painting and code associated with scrolling):

 

 

protected void subpaint(Graphics graphics) { int xOffset = buttonSpacing; for (int i = 0; i < fieldCount; i++) { Field field = getField(i); setPositionChild(field, xOffset, 0); paintChild(graphics, field); xOffset += field.getWidth() + buttonSpacing; } }

 

  Beyond that, there may well be other little bits of scaffolding you'll want to implement if you want certain behavior (such as setting the focus to the last-focused button if the user navigates back into the component).

 

  Well, HTH.

Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: BitmapFields aligning to CENTER

Hi Richard,

 

Thanks for the solution.

I also got clue for that. By defining  

HorizontalFieldManager rowHolder = new HorizontalFieldManager(NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL|

HorizontalFieldManager.FIELD_HCENTER);

 

I was getting same result.

 

Thanks for your help.

DK.