I want to have two button in the same size one in the left and the other in the right. This is my code but I get button have the width more than the other

hManager = new HorizontalFieldManager(Field.USE_ALL_WIDTH|FIELD_VCENTER);
hManager.setPadding(15, 0, 15, 15);

B1= new ButtonField("B1", Field.FIELD_LEFT | ButtonField.CONSUME_CLICK ) {

    public int getPreferredWidth() {
      return 200;
    }
};

B2= new ButtonField("B2", Field.FIELD_RIGHT | ButtonField.CONSUME_CLICK ) {

    public int getPreferredWidth() {
        return 200;
    }
};

hmanager.add(B1);
hmanager.add(B2);
有帮助吗?

解决方案

Do something like

public int getPreferredWidth() {
    return (Display.getwidth()/2)-20 ;               
}

in your ButtonField.

其他提示

Actually the problem is, For example consider the screen width is 240. But as per your code you gave 200 as width for your first button.So 240-200. Now there is 40 is the remaining screen width. So it wont consider the 200 width given for the 2nd button. So because of not enough width, By default it takes the remaining width(Not your given width). So you have to set the button width based on the screen width. And also in your code Field.Field_Right is not work. In vertical manger only you can set the horizontal property.

don't put absolute values, just portion because blackberry screen is different in a large way

@Bbdev solution is the answer in code

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top