Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 23
Registered: ‎09-04-2011
My Device: Torch 9800
My Carrier: Developer

Background scrolling problem

Hi all,

 

I'm writing code consisted of scrolling HorizontalFieldManager

 

first i create Manager with background and add it to the back

 

 

MainManager = new AbsoluteFieldManager() {
public void sublayout(int width, int height) {
super.sublayout(displayWidth, displayHeight);
}
};
MainManager.setBackground(BackgroundFactory
.createBitmapBackground(backgroundBitmap));
}

 

 

Then i add my scrolling HorizontalFieldManager to it and set background to be transparent by using this

****

MidManager.setBackground(BackgroundFactory.createSolidTransparentBackground(0x00FFFFFF, 0));

*****

 

This code works on Blackberry bold 9900 ( OS7 ) and bold 9790 ( OS7 too )

 

but when i run it on Bold9700 ( OS6 )

 

when i scroll the horizontalFieldManager, the background is reshaping ( i don't know how to explain it, maybe its rendering function did not work ) 

 

so I try to fix it by add this to my backgroundManager

 

public void paint(Graphics graphics) {
// Draw the background image and then call paint.
graphics.drawBitmap(0, 0, displayWidth, displayHeight,
backgroundBitmap, 0, 0);
super.paint(graphics);

invalidate();
}
};

 

this fix the problem but it's result in adding too much load since everytime i scroll, it'll repaint

 

If anyone know how this problem can be fixed please help me

 

Sorry for too long question

 

 

Thanks

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Background scrolling problem

You are making the old mistake of putting invalidate() inside paint(). Can you explain why you did that? Better yet, can you analyze the situation and explain why it produces the endless loop?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 23
Registered: ‎09-04-2011
My Device: Torch 9800
My Carrier: Developer

Re: Background scrolling problem

Sorry for unclear question,

 

I capture my simulator screen shot to help describing the problem

 

before.png is the background when HorizontalScroll is not scroll

after.png is the background when HorizontalScroll is scroll

 

to remind, this problem did not occur on OS7 ( In pic is BOLD9700 (OS6) )

 

Thanksbeforeafter.png

Contributor
Posts: 23
Registered: ‎09-04-2011
My Device: Torch 9800
My Carrier: Developer

Re: Background scrolling problem

anyone??

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Background scrolling problem

Sorry I have not looked hard at this, these are just some quick ideas off the top of my head. 

 

If I understand this correctly, you have a background that you wish to remain the same and the HorizontalFieldManager that you wish to scroll in front of this image.

 

I think you have used AbsoluteFieldManager in an attempt to get the Background remaining the same.  I think that is a mistake.  I would review this KB article

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

and comments which address how to get a stationary background.  But the way I do this normally is to make the MainScreen use all Height and width, have a background non scrolling VerticalFieldManager using all height and width which displays the background and then have my scrolling manager added to the background manager.

 

I suspect you could use Background to set the background Image.  But if you are going to paint the background image yourself, rather than do this in paint, I would just override paintBackground  and leave paint alone. 

 

There should be no need to set the background for contained Managers as transparent, they are transparent by default. 

 

Also this code looks dubious

 

public void sublayout(int width, int height) {
super.sublayout(displayWidth, displayHeight);
}

I think you need to check that displayWidth and displayHeight are not greater than width and height. 

 

 

New Contributor
Posts: 9
Registered: ‎05-23-2012
My Device: Bold 9700
My Carrier: turkcell

Re: Background scrolling problem

Hi SiraP,

 

did you find a solution to this problem ? 

I am facing something similar with vertical scrolling. Background image is ok when trying with 9700 but its shape corrupts when trying with 9800 or 9900...

 

Could you please share your solution if you have any ? 

 

Regards,

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Background scrolling problem

@delidumrul: Welcome to the forums!

 

I found that gesture scrolling on touch screens with stationary or custom-painted details might be problematic. One of the tricks that helped me in the past is to declare the scrolling Manager as a scroll listener and invalidate it in scrollChanged.

One of such examples can be found in the following knowledge base article:

Implementing a standard-style scrollbar

Take a look at scrollChanged implementation there. In the article, in invalidates only the relevant part of the screen, but you'll have to invalidate fully for your background to be painted correctly.

 

Good luck!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Contributor
Posts: 9
Registered: ‎05-23-2012
My Device: Bold 9700
My Carrier: turkcell

Re: Background scrolling problem

Hi,

 

thanks for the reply. I solved the problem using background image instead of drawing with the paint or paintBackground methods.

 

But i still dont understand why it works fine on 9700 and not on the others...

 

Regards,

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Background scrolling problem

"Background image is ok when trying with 9700 but its shape corrupts when trying with 9800 or 9900"

 

Is not that exactly what you would expect?  The devices are different shapes, how do you expect the image to be scaled to fit these different shapes?

 

Look at the various bitmap scaling options to see what you can do here.  But as I understand it, you will need to supply a correctly scaled (or an image with the correct aspect ratio) image. 

Highlighted
New Contributor
Posts: 9
Registered: ‎05-23-2012
My Device: Bold 9700
My Carrier: turkcell

Re: Background scrolling problem

It was not about  scaling the image. The bg image was already scaled to fit the other devices resolutions. It looks ok until i start to scroll the gridfieldmanager over the bg image. When you do that on 9700 the bg image looks ok and does not move a bit. But on the other ones, the part of the image that corresponds to the gridfieldmanager, starts to look like stretched and pixelled... Just as the screenshots show on the beginning of the topic.

But as i said, when i changed the implementation to use  background image instead of paint problem resolved. So it is ok for me now.