Таинственные лишние пиксели в ButtonField? - PullRequest
1 голос
/ 11 сентября 2011

Я создал очень простой пользовательский макет для создания меню, состоящего из ButtonFields.

Чтобы расположить их вертикально, я разделил экран на 6, а затем поместил их в деления 2,3,4 и 5, как показано в коде.

Так что для эмулятора, Torch, высота 480 будет видеть кнопки на 160, 240, 320 и 400.

Однако, когда я проверяю их, они все на 24 пикселя ниже этого, и, кажется, нет очевидной причины, если только это не типичное соглашение, которое я пропустил!

package Test;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.container.VerticalFieldManager;

class MenuLayoutManager extends VerticalFieldManager{

public MenuLayoutManager()
{
    super();
}

public int getPreferredWidth()
{
    int preferredWidth = Display.getWidth();
    return preferredWidth;
}

protected void sublayout(int inMaxWidth, int inMaxHeight)
{
int xCentre = Display.getWidth()/2;
int yGap = Display.getHeight() / 6;
int xPos = 0;
int yPos = yGap * 2;
int fieldNo = this.getFieldCount();

for(int index = 0; index<fieldNo; index++)
{
Field aField = this.getField(index);
this.layoutChild(aField, inMaxWidth, inMaxHeight);
xPos = xCentre - (aField.getWidth() / 2);
this.setPositionChild(aField, xPos, yPos);
yPos += yGap;
}
this.setExtent(inMaxWidth, inMaxHeight);


}
}

------ Создание точки входа и кнопки ----

package Test;


import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;

class MyScreen extends MainScreen
{
public MyScreen(){
super(MainScreen.NO_VERTICAL_SCROLL|MainScreen.NO_VERTICAL_SCROLLBAR);
this.initialize();
}

private void initialize()
{        
    // Set the displayed title of the screen


    this.setTitle(String.valueOf("Ben's Menu"));

    MenuLayoutManager mlm = new MenuLayoutManager();
    ButtonField Button1 = new ButtonField("New Game");
    ButtonField Button2 = new ButtonField("High Scores");
    ButtonField Button3 = new ButtonField("Instructions");
    ButtonField Button4 = new ButtonField("Exit");
    mlm.add(Button1);
    mlm.add(Button2);
    mlm.add(Button3);
    mlm.add(Button4);
    this.add(mlm); 


}



}

1 Ответ

2 голосов
/ 11 сентября 2011

С MainScreen вы не получаете полную высоту экрана, выделенную для содержимого экрана.(Как минимум, IIRC, есть заголовок и разделитель.) Попробуйте вместо этого использовать FullScreen и посмотрите, что произойдет.

...