I added HorizontalFieldManager to screen with backgroundcolor and with specific width and height.And i added a labelField to hfm.But labelfield displaying at top in hfm.How can i adjust it to center.
Try This
LabelField.setMargin(Hfm height/2, 15, 0, 15);
Did you try to set the style of the labelfield to LabelField.Field_HCENTER? This should work for you
Related
I'm getting the following error when a screen should appear:
"WARNING: Cannot layout field, insufficient height or width".
Working with BB 5.0.
This screen es called from 3 different screen, and its shows 50% of the screen or 80%, depending on which screen is pushing it.
This one only have one banner at the top (field), some BasicEditField, one DateField, a vew ObjectChoiceField and at the end 2 buttons.
Why is this error showing up now? (2 days ago it didnt and is the same screen that worked fine before). Where should i check for errors?
Also, is there some limit of height or width that a screen can manage?
Code for the banner,
public static Field getBanner() {
Background bg = BackgroundFactory.createSolidBackground(Color.WHITE);
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_WIDTH | Field.FIELD_VCENTER);
final Bitmap logo = Bitmap.getBitmapResource("logo_40px.png");
BitmapField _bitmap1 = new BitmapField(logo);
int i = Display.getWidth();
i = i - logo.getWidth();
i = i / 2;
_bitmap1.setSpace(i, 5);
hfm.add(_bitmap1);
hfm.setBackground(bg);
return hfm;
}
Regards.
update:
on the screen creation i have this:
super(MainScreen.VERTICAL_SCROLL_MASK | MainScreen.VERTICAL_SCROLLBAR)
Without this, its works fine the screen. But i wont be able to scroll down, right?
You are adding both _bitmap1 and vfm to hfm, and vfm has Field.USE_ALL_WIDTH set. It would work better, I think, to add _bitmap1 to vfm.
EDIT
It may be that your logo (with the added space) is too big for the banner area on the screen. Perhaps something like this would work:
public static Field getBanner() {
Background bg = BackgroundFactory.createSolidBackground(Color.WHITE);
final Bitmap logo = Bitmap.getBitmapResource("logo_40px.png");
final BitmapField _bitmap1 = new BitmapField(logo);
_bitmap1.setSpace((Display.getWidth() - logo.getWidth()) / 2, 5);
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_WIDTH | Field.FIELD_VCENTER) {
protected void sublayout(int width, int height) {
super.sublayout(width, height);
setExtent(width, Math.min(_bitmap1.getPreferredHeight(), height));
}
}
hfm.add(_bitmap1);
hfm.setBackground(bg);
return hfm;
}
I am trying to create a LabelField with no background at all, as a transparent one. I have a background set to my screen with a bitmap and I would like to have my LabelField transparent.
I have the following code but it does not work.
BitmapField info;
EncodedImage logoBitmap = EncodedImage.getEncodedImageResource("userInfo.png");
info = new BitmapField(null, Field.FIELD_LEFT |Field.FIELD_BOTTOM);
info.setImage(logoBitmap);
AbsoluteFieldManager superMainContainer;
superMainContainer.add(info,0,200);
LabelField nameLabel = new LabelField("Name:");
nameLabel.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
superMainContainer.add(nameLabel, 10, 210);
[Updated]
Following code snippet is working on my simulator. Difference between the following one and your code is only some initialization code.
Bitmap bm = Bitmap.getBitmapResource("image.png");
BitmapField info = new BitmapField(bm, Field.FIELD_LEFT
| Field.FIELD_BOTTOM);
LabelField lbl = new LabelField("LabelField Text");
lbl.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
AbsoluteFieldManager superMainContainer = new AbsoluteFieldManager();
superMainContainer.add(info, 0, 200);
superMainContainer.add(lbl, 10, 210);
MainScreen screen = new MainScreen();
screen.add(superMainContainer);
UiApplication.getUiApplication().pushScreen(screen);
[Old]
LabelField lbl;
lbl.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
You didn't initialize the LabelField - nameLabel before applying Background.
And you don't need to set any Background instance for getting a transparent background, the default LabelField will work for this case.
I am using HorizontalFieldManager with Field.USE_ALL_WIDTH and Field.FIELD_HCENTER but Field.FIELD_HCENTER is not working below is how I am constructing HorizontalFieldManager
HorizontalFieldManager horizontalContainer = new HorizontalFieldManager(Field.USE_ALL_WIDTH | FIELD_HCENTER);
The
Field class provides the following style bits for alignment:
Horizontal alignment styles
FIELD_LEFT
FIELD_HCENTER
FIELD_RIGHT
Vertical alignment styles
FIELD_TOP
FIELD_VCENTER
FIELD_BOTTOM
The horizontal alignment styles are only recognized when a Field is added to a VerticalFieldManager, and the vertical alignment styles only apply when a Field is added to a HorizontalFieldManager. Fields added to a HorizontalFieldManager are ALWAYS aligned to the left.
Declare in the following format
HorizontalFieldManager horizontalContainer = new HorizontalFieldManager(Field.USE_ALL_WIDTH |DrawStyle.HCENTER);
Try like this in separate class and see the output:
HorizontalFieldManager hr=new HorizontalFieldManager(Field.FIELD_HCENTER);
hr.add(new LabelField("Black",Field.FOCUSABLE));
hr.add(new LabelField("Berry",Field.FOCUSABLE));
add(hr);
Enough;
I trying to set rounded border for Blackberry Bitmap field.But it is not working for me.
I overriding paint method of Bitmap field.
g.drawRoundRect(0,0,HomeScreenIcons.barcode.getWidth(),HomeScreenIcons.barcode.getHeight(), 10, 10);
How can i set Border for Bitmap field in Blackberry.
You can give a try this way:
BitmapField bitf = new BitmapField();
bitf.setBorder(BorderFactory.createRoundedBorder(new XYEdges(6,6,6,6)));
Hope this helps...
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);
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")));
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.
This should be your requirement:
It can be done simply by subtracting the widths of the items you are adding on your horizontal field manager. By default the leftButton or the first item you add on the HFM will be added on left. Then you can add your label(userName) and the rightButton in the following way:
LabelField userName = new LabelField("MaheshBabu");
HorizontalFieldManager horizontalBar = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);
horizontalBar.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
rightButton.setMargin(0, 0, 0, Display.getWidth()-rightButton.getPreferredWidth()-leftButton.getPreferredWidth()-userName.getPreferredWidth());
horizontalBar.add(leftButton);
horizontalBar.add(userName);
horizontalBar.add(rightButton);