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
Contributor
tan_mel_viso
Posts: 10
Registered: ‎06-05-2012
My Device: 9900
My Carrier: at&t

set full screen backgorund image in blackberry

using eclipse

Version: 3.6.2

BlackBerry Java SDK
Version:  7.0.0.33

 

i want to set the full screen background image in my blackberry through code

i tired this but it is always reducing image to its own size automatically even if the  image size is 496x359

 

my Code

package mypackage;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.system.*;


public final class MyScreen extends MainScreen
{
     private VerticalFieldManager verticalManager;
        private HorizontalFieldManager hrzManager;
        private Bitmap backgroundBitmap;
           
    public MyScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("MyTitle");
      //  super(NO_VERTICAL_SCROLL);

        //rather than  adding component
        //in the mainScreen add components
        //in this verticalManager and then
        //add this manager to mainScreen  
        backgroundBitmap = Bitmap.getBitmapResource("images.jpg");
        verticalManager = new VerticalFieldManager(
                          Manager.VERTICAL_SCROLL |
                          Manager.VERTICAL_SCROLLBAR)
        {
            public void paint(Graphics graphics)
            {
               //blue
                graphics.drawBitmap(0, 0, 278, 182, backgroundBitmap, 0, 0);
               //graphics.setBackgroundColor(0x000000ff);
               //graphics.clear();
               super.paint(graphics);
            }            
            protected void sublayout( int maxWidth, int maxHeight )
            {
               int width = Display.getWidth();
               int height = Display.getHeight();
               super.sublayout( width, height);
               setExtent( width, height);
            }
        };
        ButtonField button1 = new ButtonField("Button1");
        ButtonField button2 = new ButtonField("Button2");
        ButtonField button3 = new ButtonField("Button3");
        ButtonField button4 = new ButtonField("Button4");
        ButtonField button5 = new ButtonField("Button5");
        
        verticalManager.add(button1);
        verticalManager.add(button2);
        verticalManager.add(button3);
        verticalManager.add(button4);
        verticalManager.add(button5);
        this.add(verticalManager);
    }
}

 

where is image place

 

 

Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: set full screen backgorund image in blackberry

http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/decor/BackgroundFactory.htm... int, int, int) with REPEAT_SCALE_TO_FIT
----------------------------------------------------------
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
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: set full screen backgorund image in blackberry

First of all, you do need that super(NO_VERTICAL_SCROLL), but it must be the first line in your constructor.

 

Second, you should definitely go with the BackgroundFactory solution suggested by Simon. I would prefer it to the custom paint. I myself used those custom paints (better yet, paintBackground) back in 2009-2010, when I had to support OS 4.2. These days, you have all the luxuries of net.rim.device.ui.api.decor package - use them!

 

Third, I would suggest another manager without vertical scroll between your scrolling manager and your MainScreen. That non-scrolling manager would be there for the sole purpose of displaying the background and would have NO_VERTICAL_SCROLL | USE_ALL_WIDTH | USE_ALL_HEIGHT style flags. Use setBackground on it and see how it works.

 

Overall, such exercises with MainScreen are harder than they should be because of the long-standing bug in its implementation. You can read more about it here:

MainScreen explained

 

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.