开发者

setMargin method in BlackBerry

开发者 https://www.devze.com 2023-02-01 16:12 出处:网络
I have to use setMargin() method in my Blackberry application. Would any one please explain开发者_运维百科 me this method in detail?

I have to use setMargin() method in my Blackberry application. Would any one please explain开发者_运维百科 me this method in detail?

setMargin(top,right,bottom,left)

How can I use above 4 parameters to display my controls on the screen? Maybe its a very simple thing to understand but I am really very confused with the top right bottom left parameters. Maybe I am misinterpreting it and getting improper display of controls on screen.


By default field managers are aligned from left to right and from top to bottom but it is possible to change this. setMargin is relative to the field or to an object in the field on its alignment.

Bitmap bitmap = EncodedImage.getEncodedImageResource("img/image.png").getBitmap();

HorizontalFieldManager hfm = new HorizontalFieldManager();
BitmapField a = new BitmapField(bitmap);
a.setMargin(20,0,0,10);
hfm.add(a);

BitmapField b = new BitmapField(bitmap);
b.setMargin(20,0,0,10);
hfm.add(b);

add(hfm);

In the above example bitmap 'a' is positioned 20 pixels relative to the top of the field manager hfm. E.g. if this is the only field manager it is positioned 20 pixes from the top of the screen. It is positioned 10 pixels from the left of the start of hfm.

Bitmap 'b' is also positioned 20 pixels from the top of hfm and it is positioned 10 pixels from the right most pixel of bitmap 'a'. It's because we are in a (left to right) horizontal field that b is relative to a's right most pixel.

We could flip this example from right to left by realigning the manager. I.e.

HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_RIGHT);
...
a.setMargin(0,10,0,0); // positioned 10 pixels from the right

Or similarly a vertical manager

VerticalFieldManager vfm = new VerticalFieldManager();
...
a.setMargin(20,10,0,0);
...
b.setMargin(20,10,0,0);  
...

The above 'a' is aligned 20 pixels from the top of vfm and 10 pixels from the left of vfm. 'b' is aligned 10 pixels from the left of vfm and 20 pixels from the bottom of 'a'

0

精彩评论

暂无评论...
验证码 换一张
取 消