我一直在努力在Blackberry上动态创建多个VerticalFieldManager。每个子管理器将向用户显示不同的数据。每个子管理器在屏幕上的位置都不同。所以我创建了一个具有“mainManager”的类和另一个创建“子管理器”的类,然后我调用mainManager.add(new TheClassExtendingVerticalFieldManager);
将子管理器添加到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);
}
提前致谢
答案 0 :(得分:0)
试试这个:
for (int i = 0; i < 3; i++) {
theheight = theheight+100;
mainManager.add(new ProgramListView(theheight));
}
this.add(mainManager);
答案 1 :(得分:0)
只是详细说明Eugen Martynov指出的内容,mainManager
是HorizontalFieldManager
,这意味着它会按照水平添加()的顺序排列子字段。它会根据您对add()
的调用顺序自动处理布局。
但是,每个子节点都是ProgramListView
的实例并返回Display.getWidth()
getPreferredWidth():
public int getPreferredWidth() {
// TODO Auto-generated method stub
return Display.getWidth();
}
所以,第一个占据整个屏幕宽度,接下来的两个必须在右边(但你已经占用了整个屏幕宽度)。
您希望这三个ProgramListViews
垂直堆叠吗?然后,mainManager
应该只更改为VerticalFieldManager
。使用VerticalFieldManager
,为三个不同的add()
子字段调用ProgramListView
会自动将它们垂直排列。