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
New Developer
vick_man
Posts: 24
Registered: ‎07-30-2008
My Device: Not Specified
Accepted Solution

Non-scrollable background image for the MainScreen

Hi all.

 

I'm using the following code to make the background image not scrollable, and it works for all Blackberries except Storm2 (OS  5.0) (tried on simulator):

 

 

public class MyScreen extends MainScreen{

...

    public MyScreen() {
       super(NO_VERTICAL_SCROLL);
       bitmap=loadBG();
super.add(mContainer = new BGVerticalFieldManager(bitmap)); }
public void add(Field field){
mContainer.add(field);
}
... }

 

 

 

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);
    }
    
    protected void sublayout(int maxWidth, int maxHeight) {
        mBgX = (Display.getWidth() - mBgWidth) >> 1;
        mBgY = (Display.getHeight() - mBgHeight) >> 1;
    	super.sublayout(maxWidth, maxHeight);
    }

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

 

On Storm2 the background image is scrolling, seems like getVerticallScroll() does not work.

 

Anybody can help me with this?

 

Thanks.

 

Please use plain text.
Contributor
tuyennguyencanada
Posts: 41
Registered: ‎07-28-2010
My Device: Not Specified

Re: Non-scrollable background image for the MainScreen

[ Edited ]

Try these lines of code 

 

 

public class MyScreen extends MainScreen
{
  private Bitmap bkgImage = Bitmap.getBitmapResource("bkgMain.png");
 
  public MyScreen ()
  {
  this.getMainManager().setBackground(BackgroundFactory.createBitmapBackground(bkgImage));
  }
}

 

Please use plain text.
Developer
paulhaenel
Posts: 220
Registered: ‎09-09-2008
My Device: Bold 9780

Re: Non-scrollable background image for the MainScreen

also have look at this:

 

http://supportforums.blackberry.com/t5/Java-Development/Use-a-background-image-in-application-screen...

-----------

Follow me on twitter: twitter.com/paul.haenel

If your issue is resolved, please mark this thread as solved.

Set the "Solution" mark on the post which contains the answer to your question.
Please use plain text.
New Developer
vick_man
Posts: 24
Registered: ‎07-30-2008
My Device: Not Specified

Re: Non-scrollable background image for the MainScreen

tuyennguyencanada, the standart setBackground method does not work as it should.

Please use plain text.