我已经创建了一个非常基本的自定义布局来展示由ButtonFields组成的菜单。
为了垂直放置它们,我将屏幕拆分为6个,然后将它们放在divides 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);
}
}发布于 2011-09-12 01:48:39
使用MainScreen时,您无法获得分配给屏幕内容的完整显示高度。( IIRC至少要有标题和分隔符。)试着改用FullScreen,看看会发生什么。
https://stackoverflow.com/questions/7380080
复制相似问题