0

我想制作一个像这样的图像 http://i.stack.imgur.com/bB8UM.png的用户界面 。我使用垂直和水平字段管理器等基本管理器。但我的水平管理器不起作用。我得到单个图像我的水平场经理而不是两个。这是什么原因?我哪里出错了?

这是我正在使用的代码-

package mypackage;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

class TestScreen extends MainScreen{

    private VerticalFieldManager verticalManager;
    private BitmapField myBitmapField,tipOfTheDay,completeBitmapField,top30BitmapField;
    private FooterText mTextField;

    TestScreen() 
    {    
        super(NO_VERTICAL_SCROLL);

        verticalManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR)
        {
            public void paint(Graphics graphics)
            { 
                graphics.setBackgroundColor(0x00000000);
                graphics.clear();
                super.paint(graphics);
            }            
            protected void sublayout( int maxWidth, int maxHeight )
            {
                int width = Display.getWidth();
                int height = Display.getHeight();
                super.sublayout( width, height);
                setExtent( width, height);
            }
        };

        Bitmap logoBitmap = Bitmap.getBitmapResource("mybitmap1.png");
        myBitmapField = new BitmapField(logoBitmap, Field.FIELD_HCENTER);   

        verticalManager.add(myBitmapField);

        Bitmap mytipOfTheDay  = Bitmap.getBitmapResource("tipoftheday.png");

        verticalManager.add(tipOfTheDay = new BitmapField(mytipOfTheDay,Display.getWidth()));
        String text = "Lorem ipsum dolor sit amet, consectetuer \n"
            + "adipiscing elit, sed diam nonummy nibh euismod \n"
            + "tincidunt ut laoreet dolore magna aliquam erat  \n "
            + "volutpat. Ut wisi enim ad minim veniam, quis \n"
            + "nostrud exerci tation ullamcorper suscipit \n"
            + "lobortis nisl ut aliquip ex ea commodo consequat. \n"
            + "Duis autem vel eum iriure dolor in hendrerit in \n";
        verticalManager.add(mTextField = new FooterText(text, Display.getWidth(), Display.getHeight()/2));

        HorizontalFieldManager hfm = new HorizontalFieldManager();
        Bitmap complete  = Bitmap.getBitmapResource("Complete.png");
        Bitmap top30  = Bitmap.getBitmapResource("Top30.png");

        hfm.add(new BitmapField(complete));
        hfm.add(new BitmapField(top30));

        verticalManager.add(hfm);

        this.add(verticalManager);
    }
}
4

2 回答 2

1

Fields 将在下面均匀分布HorizontalFieldManager,并且s 将以HorizontalFieldManager最大允许宽度容纳其子级。

HorizontalFieldManager hfm = new HorizontalFieldManager() {
    protected void sublayout(int maxWidth, int maxHeight) {
        int w = maxWidth;
        int h = 0;
        Field f0, f1;
        if (getFieldCount() == 2) {
            f0 = getField(0);
            f1 = getField(1);

            layoutChild(f0, maxWidth / 2, maxHeight);
            layoutChild(f1, maxWidth / 2, maxHeight);

            h = Math.max(f0.getHeight(), f1.getHeight());

            setPositionChild(f0, (maxWidth/2 - f0.getWidth()) / 2, (h - f0.getHeight()) / 2);
            setPositionChild(f1, maxWidth/2 + (maxWidth/2 - f1.getWidth()) / 2, (h - f1.getHeight()) / 2);
        }
        setExtent(w, h);
    };
};
于 2012-04-23T12:30:36.537 回答
0

试试这个 -

    HorizontalFieldManager hfm = new HorizontalFieldManager(){
    protected void sublayout(int maxWidth, int maxHeight) 
      { 
      super.sublayout(Display.getWidth()/2,20);  
      setExtent(Display.getWidth()/2,20);
      }
    };
    Bitmap complete  = Bitmap.getBitmapResource("Complete.png");
    Bitmap top30  = Bitmap.getBitmapResource("Top30.png");

    hfm.add(new BitmapField(complete));
    hfm.add(new BitmapField(top30));
于 2012-04-23T12:06:02.877 回答