1

我一直在努力在 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);

    }

提前致谢

4

2 回答 2

0

尝试这个:

    for (int i = 0; i < 3; i++) {
        theheight = theheight+100;
         mainManager.add(new ProgramListView(theheight));
    }
    this.add(mainManager);
于 2012-07-17T13:13:27.290 回答
0

只是为了详细说明 Eugen Martynov 指出的内容, your mainManageris a HorizontalFieldManager,这意味着它将按照您 add() 它们的顺序水平布置子字段。它会根据您调用的顺序自动为您处理布局add()

但是,每个孩子都是一个实例,ProgramListView并在 getPreferredWidth() 中返回 Display.getWidth():

public int getPreferredWidth() {         
    // TODO Auto-generated method stub         
    return Display.getWidth();     
}

所以,第一个占据了整个屏幕宽度,接下来的两个必须在右边(但你已经占据了整个屏幕宽度)。

你想让这三个ProgramListViews垂直堆叠吗?然后,mainManager应该只是更改为VerticalFieldManager. 使用VerticalFieldManager, 调用add()三个不同的ProgramListView子字段将自动将它们垂直排列。

于 2012-07-17T20:58:41.723 回答