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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
toddbloom7
Posts: 28
Registered: ‎05-27-2009
Accepted Solution

About Background Images and Layouts

Hello everyone - two quick questions that are almost related to each other.

 

First, is there a way to make an image fixed against the canvas (similar to the background-position: fixed attribute in CSS). I have the following code - the image sits in back while some text is overlayed over it. I want the image to remain stationary while the user scrolls the text. I couldn't find a method to keep the image fixed.

 

 

HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT){ // override pain method to create the background image public void paint(Graphics graphics) { // draw the background image graphics.drawBitmap(0, 0, deviceWidth, deviceHeight, _backgroundBitmap, 0, 0); super.paint(graphics); } };

 

 Secondly, is a way to position a button/label field on the screen absolutely? I was reading about setChildPosition() but I don't think that's what I was looking for. I basically want to set up the following code so that it displays toward the bottom right of the screen to line up with a portion of the background image. I would imagine there is a way to do it but it's escaping me right now.

_playButton = new WhaleAppButtonClass("stream1button_PLAY.png", Field.FOCUSABLE);

 

Thank you in advance! 


 

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009

Re: About Background Images and Layouts

[ Edited ]

Can you make your question a little bit clear.

 

Exactly what are you trying to achieve?

 

 

Regards

Bikas

Message Edited by bikas on 05-30-2009 02:25 AM
Please use plain text.
New Developer
toddbloom7
Posts: 28
Registered: ‎05-27-2009

Re: About Background Images and Layouts

I have a background image that I want to stay stationary while the user scrolls through text - rather then having it end if the text is longer then the background image.

 

I want to be able to position elements on the screen anywhere using X and Y coordinates rather then having them right at the top left corner of the screen.

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009

Re: About Background Images and Layouts

Hi,

 

About the Backgroud image you can try something like this: 

 

import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*; public class TestScreen extends MainScreen { private VerticalFieldManager mainManager; private VerticalFieldManager subManager; private Bitmap _backgroundBitmap = Bitmap.getBitmapResource("sunset.png"); private int deviceWidth = Display.getWidth(); private int deviceHeight = Display.getHeight(); public TestScreen() { super(NO_VERTICAL_SCROLL); //this manager is used for the static background image mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR ) { public void paint(Graphics graphics) { graphics.clear(); graphics.drawBitmap(0, 0, deviceWidth, deviceHeight, _backgroundBitmap, 0, 0); super.paint(graphics); } }; //this manger is used for adding the componentes subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR ) { protected void sublayout( int maxWidth, int maxHeight ) { int displayWidth = deviceWidth; int displayHeight = deviceHeight; super.sublayout( displayWidth, displayHeight); setExtent( displayWidth, displayHeight); } }; /// add your component to this subManager///////// subManager.add(new ButtonField("Button1")); subManager.add(new ButtonField("Button2")); subManager.add(new ButtonField("Button3")); subManager.add(new ButtonField("Button4")); subManager.add(new ButtonField("Button5")); subManager.add(new ButtonField("Button6")); subManager.add(new ButtonField("Button7")); subManager.add(new ButtonField("Button8")); subManager.add(new ButtonField("Button9")); subManager.add(new ButtonField("Button10")); subManager.add(new ButtonField("Button11")); subManager.add(new ButtonField("Button12")); subManager.add(new ButtonField("Button13")); subManager.add(new ButtonField("Button14")); subManager.add(new ButtonField("Button15")); /////////////////////////////////////////////////// //add subManager over the mainManager mainManager.add(subManager); //finally add the mainManager over the screen this.add(mainManager); } }

 

 

And About setting elements  in X and Y coordinates:

 

There is no direct method for placing elements in X ,Y coordinates.

In this case you will need a custom layout manager.

 

This KB article will help you wtitting  custom layout manager.

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/... 

 

 

Regards

Bikas 

 

Please use plain text.
New Developer
toddbloom7
Posts: 28
Registered: ‎05-27-2009

Re: About Background Images and Layouts

I was afraid of the layout manager - I had already constructed something so it'd be a pain to go back and redo it but that's good to know for the future - I've bookmarked it, thanks!

 

That makes sense - so when I'm working with Blackberry I should think of it as stacking items on top of each other? The top most items will cover the bottom most items? It's a bit clearer now.

 

Thanks for the pointer in the right direction! :smileyhappy:

 

Have a good weekend!

Please use plain text.
New Contributor
gvenugopal141
Posts: 3
Registered: ‎01-04-2011

Re: About Background Images and Layouts

@bikas, first i should say thanks for your great effort as it solved my problem. But one small issue is there, if we scroll the screen vertically using the trackball it looks good but when we drag the screen vertically using touch screen, the background image is also moved along with ui components and gets modified. How can i restrict the background image to be fixed when scroll using trackbal or touch screen??

 

 

Thanks,

venu

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Carrier: various

Re: About Background Images and Layouts

Welcome to the forums!

In general, posting in solved threads is not a good way to attract attention. You have a new question - next time, post a new message.  Even if it is related, people are less likely to go investigate in solved threads.

 

To answer your question: yes, it is a known problem. I solved it by painting the background right there in the scrollable manager, but with a twist:

 

1) drawBitmap's first two parameters are getHorizontalScroll(), getVerticalScroll()

2) I set a scroll listener on that scrollable manager (actually, I create is as the listener to itself - this will require an explicit class, in order to add "implements ScrollListener") and invoke invalidate() in scrollChanged(int horizontal, int vertical).

 

You can try different variations of that.

 

Another advice for the future: if you find bikas' post useful, scroll up and click the white star on the black background next to that post. This is the forum's way of saying thanks (referred here as "kudos").

 

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!
Please use plain text.