问题描述
我在我的黑莓应用程序屏幕的背景位图。屏幕滚动已启用,因为我必须有一个滚动。我现在面临哪些问题是,当我向下滚动页面,背景位图不适合用于滚动页面,而是显示只是普通的白色背景。我们需要绘制背景位图,每滚动页面?
I have a background bitmap in my Blackberry application screen. Screen has scrolling enabled as i must to have a scroll. The problem which i'm facing is, when i scroll down the page, background bitmap doesn't fit for the scrolled page, rather it shows just plain white background. Do we need to draw the background bitmap for every scrolling page?
我的位图尺寸为:360 * 480
My bitmap size is: 360 * 480
更新code是:
class BGVerticalFieldManager extends VerticalFieldManager {
Bitmap mBgBitmap = null;
int mBgWidth = -1;
int mBgHeight = -1;
int mBgX = -1;
int mBgY = -1;
public BGVerticalFieldManager(Bitmap background) {
super(USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL
| VERTICAL_SCROLLBAR);
mBgBitmap = background;
mBgWidth = mBgBitmap.getWidth();
mBgHeight = mBgBitmap.getHeight();
mBgX = (Display.getWidth() - mBgWidth) >> 1;
mBgY = (Display.getHeight() - mBgHeight) >> 1;
}
protected void paintBackground(Graphics graphics) {
paintBackgroundBitmap(graphics);
invalidate();
}
/*private void paintBackgroundBitmap(Graphics graphics) {
if (null != mBgBitmap) {
int x = mBgX + ((MainScreen)getScreen())
.getMainManager().getHorizontalScroll();
int y = mBgY + ((MainScreen)getScreen())
.getMainManager().getVerticalScroll();
graphics.drawBitmap(x, y, mBgWidth,
mBgHeight, mBgBitmap, 0, 0);
}
} */
private void paintBackgroundBitmap(Graphics graphics) {
if (null != mBgBitmap) {
int x = mBgX
+ getHorizontalScroll();
int y = mBgY
+ getVerticalScroll();
graphics.drawBitmap(x, y, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
}
}
}
调用上面的背景位图code从另一个文件如下:
CALLING THE ABOVE BACKGROUND BITMAP CODE FROM THE ANOTHER FILE AS BELOW :
public MyFirstScreen ( String label, int screenState, int selectedObj, boolean bUI )
{
super(VERTICAL_SCROLL | VERTICAL_SCROLLBAR); // I must need it ...
appTitle = label;
setTitle(appTitle);
background = Bitmap.getBitmapResource ("HomeBack.png");
add(_container = new BGVerticalFieldManager(background));
..............................
..............................
..............................
}
推荐答案
要得到你可以使用实际的滚动位置 getVerticalScroll():
To get actual scroll position you can use getVerticalScroll():
class BGVerticalFieldManager extends VerticalFieldManager {
Bitmap mBgBitmap = null;
int mBgWidth = -1;
int mBgHeight = -1;
int mBgX = -1;
int mBgY = -1;
public BGVerticalFieldManager(Bitmap background) {
super(USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL
| VERTICAL_SCROLLBAR);
mBgBitmap = background;
mBgWidth = mBgBitmap.getWidth();
mBgHeight = mBgBitmap.getHeight();
mBgX = (Display.getWidth() - mBgWidth) >> 1;
mBgY = (Display.getHeight() - mBgHeight) >> 1;
}
protected void paintBackground(Graphics graphics) {
paintBackgroundBitmap(graphics);
invalidate();
}
private void paintBackgroundBitmap(Graphics graphics) {
if (null != mBgBitmap) {
int x = mBgX
+ getHorizontalScroll();
int y = mBgY
+ getVerticalScroll();
graphics.drawBitmap(x, y, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
}
}
}
结果
使用示例:
Sample of use:
class Scr extends MainScreen {
private BGVerticalFieldManager mContainer;
public Scr() {
super(NO_VERTICAL_SCROLL);
setTitle("Screen Title");
Bitmap bitmap = Bitmap.getBitmapResource("BoldOEM.jpg");
add(mContainer = new BGVerticalFieldManager(bitmap));
for (int i = 0; i < 100; i++) {
mContainer.add(new LabelField("List item #" + String.valueOf(i)));
mContainer.add(new NullField(FOCUSABLE));
}
}
}
这篇关于黑莓手机 - 背景位图不适合滚动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!