BlackBerryForums.com : Your Number One BlackBerry Community      

»Sponsored Links



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

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.
   
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 120
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Default 02-09-2007, 08:48 AM

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);
    }
};
   
  (#3 (permalink)) Old
Biswas Offline
New Member
 
Posts: 11
Join Date: Feb 2007
Model: 7100T
Carrier: Hutch
Default 02-10-2007, 12:02 AM

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.
   
  (#4 (permalink)) Old
dangihitesh Offline
Knows Where the Search Button Is
 
Posts: 29
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: CLDC
Post How to align an Image at the Middle pos of the BB Device Screen - 08-10-2007, 06:59 AM

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....
   
  (#5 (permalink)) Old
xxxdev Offline
Thumbs Must Hurt
 
Posts: 115
Join Date: Aug 2007
Model: 8100
PIN: N/A
Carrier: xxx
Default 08-10-2007, 02:10 PM

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
   
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-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1