02-10-2012 04:27 PM
Hello, I would like to implement an image background for my application, where it should not move even when the user scrolls down... I found the following code on internet for this kind of manager:
package com.kruger.workflow.gui; import net.rim.device.api.system.Bitmap; import net.rim.device.api.system.Display; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.container.VerticalFieldManager; public 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); } } }
However is not working... I'm getting the following results:
As you can see the image starts scrolling upside...
The usage of this manager is the following one:
Bitmap bitmap = Bitmap.getBitmapResource("1.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 SeparatorField());
}
However no results so far... While debugging the code I noticed that this line :
if (null != mBgBitmap) {
int x = mBgX
+ getHorizontalScroll();
int y = mBgY
+ getVerticalScroll();
graphics.drawBitmap(x, y, mBgWidth, mBgHeight, mBgBitmap, 0, 0);
}Is always returning 0 for both x a y, isn't suppossed that getVerticalScroll or getHorizontalScroll should return the current offset from the container manager??. How can I correct this?
Thanks a lot.
Solved! Go to Solution.
02-10-2012 11:12 PM
See this link, I posted some answer which may helps you
There mybackgroundImage is my bitmap which set as background;
==================================================
Feel free to click LIKE button if the solution helps you;
02-13-2012 11:21 AM
Hi, I implemented the code that you posted... it works, however the scrolling of the background is not fluent. What I mean is that the backgrond is respositioned completely when the whole screen has been scrolled down... giving an impression of an image "jumping" in the background. How could I correct it?. I'm testing on the 9800 OS 6 Simulator.
02-13-2012 11:43 AM
02-13-2012 11:57 AM
Thanks, it worked perfectly