BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-08-2007, 08:59 AM   #1 (permalink)
New Member
 
Join Date: Feb 2007
Model: 7100T
Carrier: Hutch
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question How to align an Image at the Middle pos of the BB Device Screen.

Please Login to Remove!

Hi,

I am begginer of BlackBerry application. I have extends FullScreen in my application. I want to display an image at the middle position of the screen. I did not find any methods to do this.
Pls Help me to go ahead.

device screen width is : 240
device screen height is : 260

and,

Image width is: 47
Image Height is :75

Thanks,

Shwarup Biswas.
Offline  
Old 02-09-2007, 09:48 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Biswas,

Here is how I handle centering a background image on the screen.

fbrimm

Code:
background = Bitmap.getBitmapResource("MyBackground.jpg");
HorizontalFieldManager myHFM = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL | HorizontalFieldManager.NO_VERTICAL_SCROLL | Manager.USE_ALL_HEIGHT) {
    //Override the paint method to draw the background image.
    public void paintBackground(Graphics graphics) {
        int startX = 0;
        int startY = 0;
                
        // Determine where to center image
        if (this.getVisibleWidth() > background.getWidth()) {
            startX = (this.getVisibleWidth() - background.getWidth()) / 2;
        }
        if (this.getVisibleHeight() > background.getHeight()) {
            startY = (this.getVisibleHeight() - background.getHeight()) / 2;
        }
                                
        //Draw the background image and then call paint.
        graphics.drawBitmap(startX, startY, background.getWidth(), background.getHeight(), background, 0, 0);
                
        super.paintBackground(graphics);
    }
};
Offline  
Old 02-10-2007, 01:02 AM   #3 (permalink)
New Member
 
Join Date: Feb 2007
Model: 7100T
Carrier: Hutch
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by fbrimm
Hello Biswas,

Here is how I handle centering a background image on the screen.

fbrimm

Code:
background = Bitmap.getBitmapResource("MyBackground.jpg");
HorizontalFieldManager myHFM = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL | HorizontalFieldManager.NO_VERTICAL_SCROLL | Manager.USE_ALL_HEIGHT) {
    //Override the paint method to draw the background image.
    public void paintBackground(Graphics graphics) {
        int startX = 0;
        int startY = 0;
                
        // Determine where to center image
        if (this.getVisibleWidth() > background.getWidth()) {
            startX = (this.getVisibleWidth() - background.getWidth()) / 2;
        }
        if (this.getVisibleHeight() > background.getHeight()) {
            startY = (this.getVisibleHeight() - background.getHeight()) / 2;
        }
                                
        //Draw the background image and then call paint.
        graphics.drawBitmap(startX, startY, background.getWidth(), background.getHeight(), background, 0, 0);
                
        super.paintBackground(graphics);
    }
};
Hi,

Thanks for your reply.

Regards,
Shwarup Biswas.
Offline  
Old 08-10-2007, 07:59 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: CLDC
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Post How to align an Image at the Middle pos of the BB Device Screen

Hi,

How can it be possible?????????

U r using HorizontalFieldManager and u r overriding paintBackground() method, but there is no paintBackground() method in HorizontalFieldManager class Hierarchy.....


How these method can be overriden?????
I did't getting it???

Plz anybody help me....
Offline  
Old 08-10-2007, 03:10 PM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Aug 2007
Model: 8100
PIN: N/A
Carrier: xxx
Posts: 117
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by fbrimm View Post
Hello Biswas,

Here is how I handle centering a background image on the screen.

fbrimm

Code:
background = Bitmap.getBitmapResource("MyBackground.jpg");
HorizontalFieldManager myHFM = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL | HorizontalFieldManager.NO_VERTICAL_SCROLL | Manager.USE_ALL_HEIGHT) {
    //Override the paint method to draw the background image.
    public void paintBackground(Graphics graphics) {
        int startX = 0;
        int startY = 0;
                
        // Determine where to center image
        if (this.getVisibleWidth() > background.getWidth()) {
            startX = (this.getVisibleWidth() - background.getWidth()) / 2;
        }
        if (this.getVisibleHeight() > background.getHeight()) {
            startY = (this.getVisibleHeight() - background.getHeight()) / 2;
        }
                                
        //Draw the background image and then call paint.
        graphics.drawBitmap(startX, startY, background.getWidth(), background.getHeight(), background, 0, 0);
                
        super.paintBackground(graphics);
    }
};
Hello, I know better way

Bitmap bmp = Bitmap.getBitmapresources (...);
BitmapField bf = new BitmapField ( bmp );
bf.setSpace (Graphics.getScreenWidth()/2 - bmp.getWidth()/2,
Graphics.getScreenHeight()/2 - bmp.getHeight()/2 );

screen.add (bf);

XXXDev
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.