开发者

BlackBerry 6.0 bitmap background using paintBackground issues with scrolling

开发者 https://www.devze.com 2023-03-25 03:28 出处:网络
I\'m having a very strange problem with a background behind a VerticalFieldManager. I have a Manager (NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL) that draws the background in paintBackground method wh

I'm having a very strange problem with a background behind a VerticalFieldManager.

I have a Manager (NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL) that draws the background in paintBackground method which has 1 child: VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR) which stores the fields that need to be scrolled.

When the VerticalFieldManager scrolls the Manager background starts moving (and its choppy). When I use the setBackground to set the background image everything works fine, but I need the support of 4.5+. Anyone experienced this before?

my screen class:

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(in开发者_开发百科t 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);
}

}


Try this one, use this code in your class constructor.

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;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消