【发布时间】:2012-07-18 04:58:41
【问题描述】:
我一直在努力在 Blackberry 上动态创建多个 VerticalFieldManager。每个 subManager 都会向用户显示不同的数据。并且每个 subManager 在屏幕上会有不同的位置。因此,我创建了一个具有“mainManager”的类和另一个创建“submanagers”的类,然后我调用mainManager.add(new TheClassExtendingVerticalFieldManager); 将 subManagers 添加到 mainManager。问题是我只得到一个 subManager 而不是三个。我正在使用填充来分隔管理器。这是我使用的代码。请指导我正确的方向,将不胜感激。
创建子管理器的类
public class ProgramListView extends VerticalFieldManager{
private VerticalFieldManager subManager;
private int _height;
public ProgramListView(int height){
this._height = height;
// subManager = new VerticalFieldManager(
// Manager.NO_HORIZONTAL_SCROLL | Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR |
// Manager.NO_HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH)
//
// {
//
//
// };
}
public int get_height() {
return _height;
}
public void set_height(int _height) {
this._height = _height;
}
public void setCoordinates(int x, int y){
setPosition(100,140);
}
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth();
int displayHeight = maxHeight;
this.setPosition(300, 300);
super.sublayout( 40, 40);
setPadding(this.get_height(), 0, 0, 0);
setExtent(displayWidth, this.get_height());
}
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.BLUE);//blue
graphics.clear();
super.paint(graphics);
}
public int getPreferredWidth() {
// TODO Auto-generated method stub
return Display.getWidth();
}
}
mainManager 类
public class ProgramLayout extends MainScreen {
private HorizontalFieldManager mainManager;
private int deviceWidth = Display.getWidth();
private int deviceHeight = Display.getHeight();
private Vector subManagers;
private int theheight;
public ProgramLayout(){
setToolbar();
subManagers = new Vector();
theheight = 100;
mainManager = new HorizontalFieldManager(Manager.VERTICAL_SCROLL | Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = deviceWidth;
int displayHeight = deviceHeight;
super.sublayout( displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.BLACK);
graphics.clear();
super.paint(graphics);
}
public int getPreferredWidth() {
// TODO Auto-generated method stub
return Display.getWidth();
}
};
for (int i = 0; i < 3; i++) {
theheight = theheight+100;
subManagers.addElement(new ProgramListView(theheight));
}
for (int i = 0; i < subManagers.size(); i++) {
mainManager.add((VerticalFieldManager)subManagers.elementAt(i));
}
this.add(mainManager);
}
提前致谢
【问题讨论】:
-
可能是因为您使用的是 HorizontalFieldManager 并且子管理器类被编程为占用所有屏幕宽度
-
只是为了详细说明 Eugen 指出的内容,您的
mainManager是HorizontalFieldManager,这意味着它将按照您add()它们的顺序排列子字段,水平。但是,每个孩子都是ProgramListView的一个实例,并在getPreferredWidth()中返回Display.getWidth()。所以,第一个占据了整个屏幕宽度。您是否希望这三个ProgramListViews垂直堆叠?那么,mainManager应该是VerticalFieldManager。 -
谢谢大家。将主经理改为垂直经理就可以了。
-
嘿@Nate 如果您将您的评论作为实际答案,我可以选择它作为正确答案。谢谢
-
按要求发布评论作为答案:)
标签: java blackberry blackberry-jde