I am new to BlackBerry Development (5.0). I have a little experience in Android Applications Development.
What I’m trying to do is fill an image on the whole screen (Horizontally)
Similar to what you could do in Android using fill_parent in a layout file.
I’ve looked on some forums to find a solution, but didn’t get a satisfactory one.
This is how I’m getting my image
Bitmap headerLogo = Bitmap.getBitmapResource("uperlogo.png");
BitmapField headerLogoField =
new BitmapField(headerLogo, BitmapField.USE_ALL_WIDTH | Field.FIELD_HCENTER);
setTitle(headerLogoField);
This code is giving me my header on top (as required) and in the center. I simply want this to stretch horizontally to cover all space.
It is possible to stretch the
Bitmaphorizontally before creating theBitmapField, and that will solve the problem. But stretchingBitmapand using it as title will create problem for devices that supports screen rotation (e.g. Storm, Torch series). In that case you have to maintain two stretchedBitmapinstance, one for the portrait mode and other for landscape mode. And you also need to write some extra code for setting the appropriateBitmapdepending on the orientation. If you don’t want to do that then check following 2 approaches:Using CustomBitmapField instance
A CustomBitmapField that can stretch
Bitmaphorizontally can be used. Check the implementation.Using Background instance
Backgroundobject can solve the problem easily. If aBackgroundinstance can be set to aHorizontalFieldManagerwhich will use all the width available to its, then in case of screen rotation it will take care of its size and background painting. And theBackgroundinstance will itself take care of the streching of the suppliedBitmap. Check the following code.