使用paintBackground滚动的BlackBerry 6.0位图背景

时间:2011-08-03 11:45:35

标签: blackberry

我在VerticalFieldManager背后有一个非常奇怪的背景问题。

我有一个管理器(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL)在paintBackground方法中绘制背景,该方法有1个子节点: VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR),用于存储需要滚动的字段。

当VerticalFieldManager滚动时,Manager背景开始移动(及其波动)。当我使用setBackground设置背景图像时,一切正常,但我需要4.5+的支持。以前有人经历过这个吗?

我的屏幕类:

public class RMainScreen extends MainScreen {
EncodedImage fon = EncodedImage.getEncodedImageResource("background_480x360.png");
HorizontalFieldManager content;
public RMainScreen() {
    super(USE_ALL_WIDTH | USE_ALL_HEIGHT | NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR);
    content = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.NO_VERTICAL_SCROLL | HorizontalFieldManager.NO_VERTICAL_SCROLLBAR) {
        protected void paintBackground(Graphics g) {
            g.drawImage(0, 0, fon.getWidth(), fon.getHeight(), fon, 0, getLeft(), getTop());
        }
    };

    VerticalFieldManager list = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLLBAR);

    for(int i=0; i<40; i++) {
        list.add(new LabelField("item from list " + i, LabelField.FOCUSABLE) {
            protected void paint(Graphics g) {
                g.setColor(Color.WHITE);
                super.paint(g);
            }
        });
    }

    content.add(list);
    add(content);
}

}

1 个答案:

答案 0 :(得分:0)

试试这个,在类构造函数中使用此代码。

Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
        final Bitmap topBg1 = resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
        VerticalFieldManager vfmTop = new VerticalFieldManager(Field.USE_ALL_WIDTH | USE_ALL_WIDTH)
        {
            protected void paintBackground(Graphics graphics) 
            {
                graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );             
                super.paint(graphics);
            }
            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                super.sublayout(topBg1.getWidth(), topBg1.getHeight());
                setExtent(topBg1.getWidth(), topBg1.getHeight());
            }

        };

public static Bitmap resizeBitmap(Bitmap image, int width, int height)
    {

        int rgb[] = new int[image.getWidth() * image.getHeight()];
        image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());     
        int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);     
        Bitmap temp2 = new Bitmap(width, height);
        temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
        return temp2;
    }