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
New Developer
Posts: 9
Registered: ‎03-11-2009
My Device: Not Specified

Setting a fixed background image for GridFieldManager

On Storm (360x480)

have created a GridFieldManager with

Rows = 200

Columns = 4

where each cell has

width = 90px

height = 90px

 

i would like to create a background image for this grid.

 

i have tried using

GridFieldManager gridFieldManager = new GridFieldManager(200, 4, GridFieldManager.FIXED_SIZE );

EncodedImage testImage = EncodedImage.getEncodedImageResource("img/backgroundImage.png");

gridFieldManager.setBackground(BackgroundFactory.createBitmapBackground(testImage.getBitmap()));

VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH); 
vfm.add(gridFieldManager);    
add(vfm);

 

where backgroundimage.png is 360x480 and fits the whole screen.

 

When i scroll down the last row in the display, the background image also scrolls up and brings in another background images.

How can the background image be made to be FIXED while the grid scrolls ?

 

Looking fwd for a reply

 

Developer
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: Setting a fixed background image for GridFieldManager

did u tried to override the paint method of GridFieldManager and draw the image inside it.

 

GridFieldManager gridFieldManager = new GridFieldManager(200, 4, GridFieldManager.FIXED_SIZE )

 {

    final Bitmap back  = Bitmap.getBitmapResource("back.png");

    paint(Graphics g)

     {

         g.drawBitmap(0,0,back.getWidth(),back.getHeight(),back,0,0);

      }

 }

 

//if u r using encoded image u can convert that to bitmap and then use it

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

Re: Setting a fixed background image for GridFieldManager

Try setting the background in vfm rather than gridFieldManager.

----------------------------------------------------------
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 Developer
Posts: 9
Registered: ‎03-11-2009
My Device: Not Specified

Re: Setting a fixed background image for GridFieldManager

thanks for your replies.

Hi Swati,
I tried what you said but that does not seem to work because


 g.drawBitmap(0,0,back.getWidth(),back.getHeight(),back,0,0);

draws the bitmap from (0,0) to (480,360)


and as we scroll down below pixel number 480, i am seeing blank(white) background

 

Hi Arkadyz,
I tried your suggestion too,

 

vfm.setBackground(BackgroundFactory.createBitmapBackground(testImage.getBitmap()));

but it has the same effect as

gridFieldManager.setBackground(BackgroundFactory.createBitmapBackground(testImage.getBitmap()));

 

essentially, as i scroll down
1) the background image also scrolls up
2) New background image which is below the first background image, starts to show up.

 

What i want is
1) The background image should not scroll ie it should remain where it is
2) The rows of the gridfieldmanager should scroll

 

looking fwd for your help

note :- I am using GridFieldManager available in 5.0.0

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

Re: Setting a fixed background image for GridFieldManager

I guess you can createBitmapBackground with four parameters -

BackgroundFactory.createBitmapBackground(testImage.getBitmap(), Background.POSITION_X_LEFT, Background.POSITION_Y_TOP, Background.REPEAT_NONE)

 

and see if it changes anything.

 

One last thing to try:

Have a non-scrolling Manager (VerticalFieldManager(NO_VERTICAL_SCROLL)) with your Background and then add your vfm (now without background) to it and your gridFieldManager (also without background) to your vfm.

 

This adds another Manager to the hierarchy but should work.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!