views:

1034

answers:

3

Hello BB experts,

I am programmatically drawing the background image(320*480 size) for my application home screen as below. Screen does have scrollbar facility added. Also screen is having many other controls too like Label, EditField etc in multiple horizontal manager.

My problem is, when i scroll down the screen, the background image is not occupying into the below scrolled portion too, instead i'm seeing white normal background. It doesn't look good. So i want to know how can i place the background image even when the screen is scrolling down?

    public MyHomescreen() 
    {    
       super();
       LabelField appTitle = new LabelField ("MyApp Title");
       setTitle(appTitle);

       background = Bitmap.getBitmapResource ("HomeScreen.png");

       _container = new VerticalFieldManager( Manager.VERTICAL_SCROLL 
            | Manager.VERTICAL_SCROLLBAR ) {
       protected void paint( Graphics g )
       {

            int y = MyHomescreen.this.getMainManager().getVerticalScroll();
            g.clear();
            g.drawBitmap( 0, 0, background.getWidth(), 
                background.getHeight(), background, 0, 0 );

            super.paint( g );
       }
       protected void sublayout( int maxWidth, int maxHeight )
       {
            int width = background.getWidth();
            int height = background.getHeight();        
            super.sublayout( width, height);
            setExtent( width, height);
       }

      }; 
      mainVerticalManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL
            | Manager.VERTICAL_SCROLLBAR)
        {
            protected void sublayout( int maxWidth, int maxHeight )
            {
                int width = background.getWidth();
                int height = background.getHeight();        
                super.sublayout( width, height);
                setExtent( width, height);
            }
        };
      // code to add manager into the screen etc..
}
+1  A: 

Take a look at this forum post for some code on how to do this using two nested VerticalFieldManagers.

Marc Novakowski
Hello, That link containing code didn't solve me the problem at all. In fact, that code does nothing for my requirement. After added that code, observed from result is that it doesn't create scrollbar for the screen, that's all. I want to have a scroll bar as well as want to stretch the background image even when scrolling is happening (or) some particular controls(ListField etc) are selected. Final result what i want is, don't want to see any white background patch anywhere in the screen when there is some constant background image placed.
Just a not, i am working for BB Storm device.
Oh - so you want to "tile" your image, not just have it as a static background?
Marc Novakowski
Yes. Doesn't BB support realigning back image automatically when background image set as static? Then what is the actual screen size in Blackberry? Is it not 320*480? If i scroll, does it go beyond it? Why don't it take my 320*480 background image even when i scroll the screen?
I want to put more fields in the screen, so i need scrollbar must.
There are many different screen sizes for BlackBerry, depending on the model. There is no API (that I know of) that will automatically do background image tiling for you - it's something you need to do manually.
Marc Novakowski
A: 

Unfortunately, you can't get an image to automatically reposition itself for you. You would have to redraw the image once you scroll past the end of your image.

We had this same problem and we tried to redraw the background, but a problem we kept running into was the positioning of the GUI elements on the always changing background. (If you have a label with white text, it might look fine to start with, but when you scroll and the background moves too, it might overlap a white portion of your background, or some other similar problems). We decided to just not have any scrolling screens and keep the interface simple and have buttons that launch other screens with more elements. That way, they're not all on one screen with a user having to scroll a lot, and it solves the background image problem

OTisler
A: 

I solved this once. Not sure about the details.
If memory serves, I either did one of two things: A) set the background on the MainScreen, parent a manager to the mainscreen and make it's fields and background translucent; which required a paint override. In essence you set the opacity and draw the image. Leave it up the to the HFM/VFM to draw over the top.
B) draw over the top of the HFM/VFM but set the opacity as to primarily show the fields of focus...

doc taco