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);
}
};
|
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