I've just started learning to develop blackberry apps and I've hit a bit of a snag. I'm unsure how I could move around a background image that is large than the field/manager it is being applied to. Here's an image to illustrate what I mean:
So far I have tried adding a Bitmap to a BitmapField inside a AbsolutePositionManager thinking I would be able to set the size of the absolute manager and just move the bitmapfield around inside it. That isn't the case, the manage just takes the size of the content inside it :(
I come from a frontend web dev background so what I'm looking for is something that behaves similar to the 'background-position' attribute in css or some sort of image mask.
Thanks in advance!
-- update --
This is a code sample of where I have got to. I now have a custom sized manager that displays a chunk of a larger BitmapField. I just need a way to move that BitmapField around.
package mypackage; import net.rim.device.api.system.Bitmap; import net.rim.device.api.ui.component.BitmapField; import net.rim.device.api.ui.container.AbsoluteFieldManager; public class MyImage extends AbsoluteFieldManager { protected void sublayout(int maxWidth, int maxHeight){ int displayWidth = 326; int displayHeight = 79; super.sublayout(displayWidth, displayHeight); setExtent(displayWidth, displayHeight); } public MyImage(){ Bitmap _image = Bitmap.getBitmapResource("img.jpg"); BitmapField image = new BitmapField(_image); add(image); } }
Rather than adding it as a Field, just store a reference to it somewhere in your Manager and then paint it yourself. Here's an untested example:
public class MyManager extends VerticalFieldManager() {
Bitmap _bg;
public MyManager() {
_bg = Bitmap.getBitmapResource("img.jpg");
}
protected void paint(Graphics graphics) {
graphics.drawBitmap(x_offset, y_offset, _bg.getWidth(), _bg.getHeight(), _bg, 0, 0);
super.paint(graphics);
}
}
Now you can just set x_offset and y_offset to whatever you want and it'll be shifted. If you need to mess with the size of the Manager to fit the Bitmap, add:
protected void sublayout(int width, int height) {
super.sublayout(width, height);
setExtent(Math.min(width, Math.max(getWidth(), _bg.getWidth())), Math.min(height, Math.max(getHeight(), _bg.getHeight()));
}
Hope this helps!