首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ButtonField中的神秘额外像素?

ButtonField中的神秘额外像素?
EN

Stack Overflow用户
提问于 2011-09-12 01:39:41
回答 1查看 82关注 0票数 1

我已经创建了一个非常基本的自定义布局来展示由ButtonFields组成的菜单。

为了垂直放置它们,我将屏幕拆分为6个,然后将它们放在divides 2、3、4和5处,如代码所示。

因此,对于模拟器,Torch,高度为480将看到160,240,320和400的按钮。

然而,当我检查它们时,它们都比这个值低24像素,似乎没有什么明显的原因,除非这只是我错过的一个典型约定!

代码语言:javascript
复制
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);


}
}

-入口点和按钮创建

代码语言:javascript
复制
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); 


}



}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-12 01:48:39

使用MainScreen时,您无法获得分配给屏幕内容的完整显示高度。( IIRC至少要有标题和分隔符。)试着改用FullScreen,看看会发生什么。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7380080

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档