05-29-2009 03:17 PM
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!
Solved! Go to Solution.
05-29-2009 04:24 PM - edited 05-29-2009 04:25 PM
Can you make your question a little bit clear.
Exactly what are you trying to achieve?
Regards
Bikas
05-29-2009 04:26 PM
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.
05-29-2009 06:29 PM
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.
Regards
Bikas
05-29-2009 09:18 PM
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! ![]()
Have a good weekend!
01-06-2011 09:21 PM
@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
01-07-2011 11:05 AM
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!