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
david_schwartz_bb
Posts: 137
Registered: ‎02-04-2010
My Device: Tour 9630
Accepted Solution

bitmap on top of screen

I would lke to display a bitmap png file, 48x48px, on top of a MainScreen and all it's field managers. The bitmap should always be on top of but not push down then fields. Basically the user would scroll the screen but the bitmap would remain in a fixed location.
What is the recommended approach?
Thanks
Developer
pankajace12
Posts: 206
Registered: ‎04-30-2011
My Device: BlackBerry Z10

Re: bitmap on top of screen

Hi

 

There is two for this.

 

1) set an images a title.

 

setTitle(new BitmapField(Bitmap.getBitmapResource("icon.png)));

 

2) Take two manager, 

 

Add image in first manager, and rest thing (UI) add in other manager, and make scrollable the second manager only, so that first manager will not get scroll.

Thanks

Pawan 

New Developer
david_schwartz_bb
Posts: 137
Registered: ‎02-04-2010
My Device: Tour 9630

Re: bitmap on top of screen

Thanks. I want to have the bitmap over the area that scrolls but the bitmap will not move. Fr example if there is a ListObject on the form it would scroll under the bitmap but the bitmap would only be on one side of screen.
New Developer
david_schwartz_bb
Posts: 137
Registered: ‎02-04-2010
My Device: Tour 9630

Re: bitmap on top of screen

bb_screen_sample.png

 

Here is the effect I am trying to acheive.

The screen would scroll like a ListObject but the Title Area and Black area would not scroll.

i.e., theListObject would scroll under the black area.

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

Re: bitmap on top of screen

[ Edited ]

See the following KB article to understand how to do this:

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

 

In brief, you will add the title area as a banner (setBanner) and you will add a non scrolling VerticalFieldManager to the MainScreen that has the bitmap map with the black corner as a background.  Then you will add a scrolling VerticalFieldManager to the non scrolling one and add the ListField to that. 

 

Actually that is how you would do it normally, but there is a problem with ListField in that each row typically paints itself completely.  I have never tried to have the rows 'transparent' and that might have readability issues with some of the data.  but give it a go and see how it turns out.

 

Good luck

 

Edit: Apologies, I missed this comment:

" theListObject would scroll under the black area"

See what arkadyz has to say below. 

 

New Developer
david_schwartz_bb
Posts: 137
Registered: ‎02-04-2010
My Device: Tour 9630

Re: bitmap on top of screen

Thanks Peter.
Your approach would put the BitMap behind the list - correct?
I want to BitMap to always be on top of everything else on the screen - or at least appear that way.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: bitmap on top of screen

In this specific case you'll have to override paint of your non-scrolling Manager. I hope your Bitmap is transparent - otherwise it will completely obscure the contents of the screen :smileyhappy:.

Something like this should solve your problem:

1. Create your MainScreen with NO_VERTICAL_SCROLL flag (read the article Peter mentioned for explanation).

2. Add the top part of the screen as a banner using MainScreen's setBanner (setTitle has its own problems - again, read that article).

3. Add a non-scrolling Manager (either VerticalFieldManager or HorizontalFieldManager will work) with USE_ALL_HEIGHT and USE_ALL_WIDTH to the screen. This manager will override its paint like this:

protected void paint(Graphics g) {
  super.paint(g);
  g.drawBitmap(0, 0, yourBitmap.getWidth(), yourBitmap.getHeight(), yourBitmap, 0, 0);
}

4. Add a VERTICAL_SCROLL (and optionally VERTICAL_SCROLLBAR) VerticalFieldManager to the Manager above.

5. Add your ListField to this vertically scrolling manager.

 

If your Bitmap gets distorted on gesture scrolling on touchscreen devices, you will have to add a scroll listener to the scrolling manager and invalidate the non-scrolling one with the overridden paint inside scrollChanged.

 

See if it works. 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 Developer
david_schwartz_bb
Posts: 137
Registered: ‎02-04-2010
My Device: Tour 9630

Re: bitmap on top of screen

One detail I left out: image needs to be clickable. How to add that to paint method?
Thanks
Developer
pankajace12
Posts: 206
Registered: ‎04-30-2011
My Device: BlackBerry Z10

Re: bitmap on top of screen

New Developer
david_schwartz_bb
Posts: 137
Registered: ‎02-04-2010
My Device: Tour 9630

Re: bitmap on top of screen

Thanks.
What I am missing is how to add the clickable bitmap via the suh paint().
Paint has methods to draw.