Blackberry - Issue with background image when scrolling down the screen
I am programmatically drawing the background image(320*480 size) for my application home screen as below. Screen does have scrollbar facility added. Also screen is having many other controls too like Label, EditField etc in multiple horizontal manager.
My problem is, when i scroll down the screen, the background image is not occupying into the below scrolled portion too, instead i'm seeing white normal background. It doesn't look good. So i want to know how can i place the background image even when the screen is scrolling down?
public MyHomescreen()
{
super();
LabelField appTitle = new LabelField ("MyApp Title");
setTitle(appTitle);
background = Bitmap.getBitmapResource ("HomeScreen.png");
_container = new VerticalFieldManager( Manager.VERTICAL_SCROLL
| Manager.VERTICAL_SCROLLBAR ) {
protected void paint( Graphics g )
{
int y = MyHomescreen.this.getMainManager().getVerticalScroll();
g.clear();
g.drawBitmap( 0, 0, background.getWidth(),
开发者_高级运维 background.getHeight(), background, 0, 0 );
super.paint( g );
}
protected void sublayout( int maxWidth, int maxHeight )
{
int width = background.getWidth();
int height = background.getHeight();
super.sublayout( width, height);
setExtent( width, height);
}
};
mainVerticalManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL
| Manager.VERTICAL_SCROLLBAR)
{
protected void sublayout( int maxWidth, int maxHeight )
{
int width = background.getWidth();
int height = background.getHeight();
super.sublayout( width, height);
setExtent( width, height);
}
};
// code to add manager into the screen etc..
}
Take a look at this forum post for some code on how to do this using two nested VerticalFieldManagers.
Unfortunately, you can't get an image to automatically reposition itself for you. You would have to redraw the image once you scroll past the end of your image.
We had this same problem and we tried to redraw the background, but a problem we kept running into was the positioning of the GUI elements on the always changing background. (If you have a label with white text, it might look fine to start with, but when you scroll and the background moves too, it might overlap a white portion of your background, or some other similar problems). We decided to just not have any scrolling screens and keep the interface simple and have buttons that launch other screens with more elements. That way, they're not all on one screen with a user having to scroll a lot, and it solves the background image problem
I solved this once. Not sure about the details.
If memory serves, I either did one of two things:
A) set the background on the MainScreen, parent a manager to the mainscreen and make it's fields and background translucent; which required a paint override. In essence you set the opacity and draw the image. Leave it up the to the HFM/VFM to draw over the top.
B) draw over the top of the HFM/VFM but set the opacity as to primarily show the fields of focus...
Another possibilty is to set a background image that has an very large vertical scroll. So when user scrolls down, the user sees bottom of image.
精彩评论