Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Regular Contributor
Posts: 60
Registered: ‎02-24-2011
My Device: Not Specified
Accepted Solution

Static background with VerticalFieldManager

Hello, I would like to implement an image background for my application, where it should not move even when the user scrolls down... I found the following code on internet for this kind of manager:

 

package com.kruger.workflow.gui;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class BGVerticalFieldManager extends VerticalFieldManager {
    Bitmap mBgBitmap = null;
    int mBgWidth = -1;
    int mBgHeight = -1;
    int mBgX = -1;
    int mBgY = -1;

    public BGVerticalFieldManager(Bitmap background) {
        super(USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL
                | VERTICAL_SCROLLBAR);
        mBgBitmap = background;
        mBgWidth = mBgBitmap.getWidth();
        mBgHeight = mBgBitmap.getHeight();
        mBgX = (Display.getWidth() - mBgWidth) >> 1;
        mBgY = (Display.getHeight() - mBgHeight) >> 1;
       
    }

    protected void paintBackground(Graphics graphics) {
        paintBackgroundBitmap(graphics);
        invalidate();
    }

    private void paintBackgroundBitmap(Graphics graphics) {
        if (null != mBgBitmap) {
        	
            int x = mBgX
                    + getHorizontalScroll();
            
            int y = mBgY
                    + getVerticalScroll();
             graphics.drawBitmap(x, y, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
        }
    }
}

 However is not working... I'm getting the following results:

 

ayuda1.png

 

ayuda2.png

 

As you can see the image starts scrolling upside...

The usage of this manager is the following one:

 

Bitmap bitmap = Bitmap.getBitmapResource("1.jpg");
        add(mContainer = new BGVerticalFieldManager(bitmap));
        for (int i = 0; i < 100; i++) {
            mContainer.add(new LabelField("List item #" + String.valueOf(i)));
            mContainer.add(new SeparatorField());
        }
    	

 However no results so far... While debugging the code I noticed that this line :

 

if (null != mBgBitmap) {
        	
            int x = mBgX
                    + getHorizontalScroll();
            
            int y = mBgY
                    + getVerticalScroll();
             graphics.drawBitmap(x, y, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
        }

 Is always returning 0 for both x a y, isn't suppossed that getVerticalScroll or getHorizontalScroll should return the current offset from the container manager??. How can I correct this?

Thanks a lot.

Developer
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: Static background with VerticalFieldManager

See this link, I posted some answer which may helps you

 

Internal Scrolling

 

There  mybackgroundImage  is my bitmap which set as background;

 

===========================================================================

Feel free to click LIKE button if the solution helps you;

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Regular Contributor
Posts: 60
Registered: ‎02-24-2011
My Device: Not Specified

Re: Static background with VerticalFieldManager

Hi, I implemented the code that you posted... it works, however the scrolling of the background is not fluent. What I mean is that the backgrond is respositioned completely when the whole screen has been scrolled down... giving an impression of an image "jumping" in the background. How could I correct it?. I'm testing on the 9800 OS 6 Simulator.

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Static background with VerticalFieldManager

i use a vfm with USE_ALL_HEIGHT and NO_VERTICAL_SCROLL and set the background picture to this (using BackgroundFactory since 5.0)

in this vfm i put a second one, but this with VERTICAL_SCROLL. The listfield (or other content) is put in there.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 60
Registered: ‎02-24-2011
My Device: Not Specified

Re: Static background with VerticalFieldManager

Thanks, it worked perfectly