views:

1029

answers:

4

I had created a HorizontalFieldManager & added BitmapFields in that.

In Blackberry Storm, Display.getWidth() is 480. In that I want to use first 450 to add some BitmapFields at LHS of screen which I m creating at runtime & add 2 BitmapFields at start at RHS of Screen.

2 BimapFields which I want to show at start r added in Constructor & other BitmapFields which I m creating at run time r added afterwords like..

class MyCanvas extends MainScreen
{

  MyCanvas()
  {

       hfm_BitmapField = new HorizontalFieldManager(){
             protected void sublayout(int maxWidth, int maxHeight) {
             super.sublayout(maxWidth, maxHeight);
             setExtent(Display.getWidth()-30, 60);
             }
         };


         startBitmap = Bitmap.getBitmapResource("start.png");
         startBitmapField = new BitmapField(startBitmap, BitmapField.ACTION_INVOKE |            BitmapField.FIELD_HCENTER | BitmapField.FIELD_RIGHT);
         hfm_BitmapField.add(startBitmapField);

         endBitmap = Bitmap.getBitmapResource("end.png");
         endBitmapField = new BitmapField(endBitmap, BitmapField.ACTION_INVOKE |            BitmapField.FIELD_HCENTER | BitmapField.FIELD_RIGHT);
         hfm_BitmapField.add(endBitmapField);

         drawBitmap();
 }


 public void drawBitmap()
 {
      bitmap[i] = new Bitmap(50, 50);
      Graphics g = new Graphics(bitmap[i]);
      g.drawLine(5,5,25,25);
      bitmapField[i] = new BitmapField(bitmap[i]);

      synchronized(UiApplication.getEventLock()) { hfm.add(bitmapField[i]); }
 }

I want startBitmapField & endBitmapField at RHS & bitmapField[i] which I m creating at runtime at LHS of HorizontalFieldManagers.

I m thinking to add 2 HorizontalFieldManagers. 1 for bitmapField[i] & 1 for startBitmapField & endBitmapField. But how to add 2 HorizontalFieldManagers or any other FieldManagers in a row?

Any solution? How to do it?

+4  A: 

You can put the 2 horizontal field managers inside another HorizontalFieldManager.

DaveJohnston
Hey DaveJohnston,Thanks a lot.. It solved my problem...
Shreyas
You should mark the answer as the correct solution if it solved your problem. Thanks :D
DaveJohnston
A: 

But how to add a ButtonField RIGHT & VCENTER aligned in a HorizontalFieldManager.

I m adding like...

hfm = new HorizontalFieldManager(){
        protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(maxWidth, maxHeight); 
                setExtent(Display.getWidth(), 60);
                }
     };

deleteButton = new ButtonField("Delete", ButtonField.FIELD_RIGHT | BitmapField.FIELD_VCENTER | ButtonField.ACTION_INVOKE);
hfm.add(deleteButton);

But its not coming with the specified alignments.

Whats the problem? Any solution?

Shreyas
A: 

Now its coming RIGHT aligned by adding

hfm = new HorizontalFieldManager(HorizontalFieldManager.FIELD_VCENTER | HorizontalFieldManager.FIELD_RIGHT);

deleteButton = new ButtonField("Delete", ButtonField.ACTION_INVOKE | ButtonField.FIELD_VCENTER | ButtonField.FIELD_RIGHT);
hfm.add(deleteButton);

But its not coming VCENTER aligned. Why so?

Shreyas
+2  A: 

Rather than use the alignment flags try adding to your sublayout method.

For each child of your Manager (hfm) you need to call setPositionChild. So if you want it right aligned and vertically centred you would do something like:

setPositionChild(deleteButton, hfm.getPreferredWidth() - deleteButton.getPreferredWidth(), (hfm.getPreferredHeight() / 2) - (deleteButton.getPreferredHeight() / 2));

This would set the top left hand corner of the delete button to be at the correct position such that it is right aligned and vertically centred within the hfm.

DaveJohnston
Thanks DaveJohnston. It solved my problem...I also marked the answers as Correct..Thanks a lot for the correct solutions....
Shreyas
I marked ur answer as correct but as my reputation is below 15 I cant vote u.
Shreyas