BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   trouble with background (http://www.blackberryforums.com/developer-forum/195044-trouble-background.html)

Morion 06-26-2009 08:58 AM

trouble with background
 
I want to have a background in my app. Here is the code.
Code:

       
private void createUI(){
                backGround = Bitmap.getBitmapResource("bg.jpg");
                myManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR){
                        public void paint(Graphics graphics){
                                graphics.clear();
                                graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backGround, 0, 0);
                                super.paint(graphics);
                        }
                };
               
                add(myManager);
        }

In the debug mode i see, that backGround is not null. But i cannot see my background picture on the display of simulator. Any ideas?

P.S. I use Eclipse. And please, dont tell me about Background class. I want to do it using 4.5.0 APIs.

Dougsg38p 06-26-2009 09:54 AM

Are you adding any fields to the manager? If not, the extent of the manager is 0,0 and you will not see your background.

Did you try the Screen.paintBackground() method?

Morion 06-26-2009 10:07 AM

Hmm... Thanks for advice. I tried to add a LabelField. Part of my background image appears only under this field. Is there any way to draw only background picture without adding elements?

Dougsg38p 06-26-2009 11:12 AM

Not with Manager. You'll need to paint the background on the screen, as I indicated in the previous post. What you are seing is expected behavior, since the manager adaptes it's extent to the extent of the field(s).

Another possibility is to add the background as a BitmapField, then paint over the background in the paint() method of the screen.

It all depends on what you are trying to accomplish.

koic 06-26-2009 11:25 AM

And be prepared to see some not pained paddings.

Morion 06-26-2009 11:31 AM

I want to make a static background in application. And i've just tried to override paintBackground() and pain() methods for my screen. Result - thin line of my background image at the top of the screen. When i added a LabelField to my screen, it appears after this thin line with default white background.

Dougsg38p 06-26-2009 01:19 PM

Post some code.

Morion 06-29-2009 01:43 AM

Hi, sorry for late post. Here's my code.
Code:


public class Screen extends MainScreen{
        private Bitmap backGround;
       
        public Screen(){
                super(NO_VERTICAL_SCROLL);
                setTitle("This is a test");
                createUI();
        }
       
        private void createUI(){
                backGround = Bitmap.getBitmapResource("bg.jpg");
                add(new LabelField("YO!", USE_ALL_WIDTH ));
        }

        protected void paintBackground(Graphics graphics){
                graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backGround, 0, 0);
                super.paintBackground(graphics);
        }
       
       
//        protected void paint(Graphics graphics){
//                super.paint(graphics);
//        }

        public boolean onClose(){
                Dialog.alert("Bye!");
                System.exit(1);
                return true;
        }


Morion 06-29-2009 05:18 AM

Yahoo! I've just made this. Here's code.
Code:

        private void createUI(){
                backGround = Bitmap.getBitmapResource("bg.jpg");
                myManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR){
                        public void paint(Graphics graphics){
                                graphics.clear();
                                graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backGround, 0, 0);
                                super.paint(graphics);
                        }
                };
               
                mainManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR){
                        protected void sublayout(int maxWidth, int maxHeight){
                                int displayWidth = deviceWidth;
                                int displayHeight = deviceHeight;
                               
                                super.sublayout(displayWidth, displayHeight);
                                setExtent(displayWidth, displayHeight);
                        }
                };
               
                myManager.add(mainManager);
                add(myManager);
               
        }



All times are GMT -5. The time now is 09:22 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.