Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BlackBerry HorizontalFieldManager alignment

Tags:

blackberry

Horizontally, I want to display two bitmaps, and between them display a label field. The code seems straightforward, but all the fields are added on the left side of the screen.

HorizontalFieldManager hfm = new HorizontalFieldManager();

callbmp = new BitmapField(ei.getBitmap(),Field.FOCUSABLE |BitmapField.FIELD_LEFT);
LabelField NAME = new LabelField("mylable", LabelField.FIELD_HCENTER);
mailbmp = new BitmapField(mail.getBitmap(),Field.FOCUSABLE|BitmapField.FIELD_RIGHT);
hfm.add(callbmp);
hfm.add(NAME);
hfm.add(mailbmp);
add(hfm);
like image 473
Mahesh Babu Avatar asked Sep 10 '26 19:09

Mahesh Babu


2 Answers

 Manager customManager = new Manager(0)
 {
     protected void sublayout(int width, int height) {
         setPositionChild(
             getField(0), 
             0, 
             0);
         layoutChild(
             getField(0), 
             getField(0).getPreferredWidth(), 
             getField(0).getPreferredHeight());

         setPositionChild(
             getField(1), 
             Graphics.getScreenWidth()/2 - getField(1).getPreferredWidth()/2, 
             0);
         layoutChild(
             getField(1), 
             getField(1).getPreferredWidth(), 
             getField(1).getPreferredHeight());    

         setPositionChild(
             getField(2), 
             Graphics.getScreenWidth() - getField(2).getPreferredWidth(), 
             0);
         layoutChild(
             getField(2), 
             getField(2).getPreferredWidth(), 
             getField(2).getPreferredHeight());    

         setExtent(width, height);
     }      
 };

 customManager.add(new BitmapField(Bitmap.getBitmapResource("image1.png")));
 customManager.add(new LabelField("Hello Alignment"));
 customManager.add(new BitmapField(Bitmap.getBitmapResource("image2.png")));
like image 59
Ashraf Bashir Avatar answered Sep 12 '26 08:09

Ashraf Bashir


HorizontalFieldManager lays out the fields left-to-right in the order in which they are added. The style bits for horizontal layout are ignored.

If you want left, right and center on a horizontal line, you'll need a custom manager.

like image 40
Michael Donohue Avatar answered Sep 12 '26 08:09

Michael Donohue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!