Thursday, October 8, 2009

how to set background image in VerticalFieldManager.

As we use color in background of VeticalFieldManager we can also use Images in background.use the following sample code to draw background images in verticalFieldManeger.
class MSBMainScreen extends MainScreen
{
/*MSBMainScreen can be use as the base class for the other UserInterface Screen of your application. when you create new class for UI Screen just extend your class to MSBMainScreen*/
private VerticalFieldManager _container;//instance of VerticalFieldManager
private Bitmap _BG;
/* instace of Bitmap to be draw in VerticalFieldManager paint method */

public MSBMainScreen()
{
super();

setTitle( "Main Screen Background Hack" );

_BG = Bitmap.getBitmapResource( "background.png" );

_container = new VerticalFieldManager( Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR ) {
protected void paint( Graphics g )
{
// Instead of these next two lines, draw your bitmap
int y = MSBMainScreen.this.getMainManager().getVerticalScroll();

g.drawBitmap( 0, y, _BG.getWidth(), _BG.getHeight(), _BG, 0, 0 );

super.paint( g );
}

// The keydown and navigation overrides are a workaround
// for an optimization hack RIM performed, perhaps assuming that
// Managers would not try to take control of painting on
// a MainScreen.
protected boolean keyDown( int keycode, int status )
{
invalidate();

return super.keyDown( keycode, status );
}

protected boolean navigationMovement( int dx, int dy, int status, int time )
{
invalidate();

return super.navigationMovement( dx, dy, status, time );
}
};

super.add( _container );
}


public void add( Field field )
{
_container.add( field );
}

public void delete( Field field )
{
_container.delete( field );
}

// Implement the rest of the field manipulation functions to redirect ro the new container

}

3 comments:

  1. Hello,
    Nice blog i like it
    The latest Blackberry Storm is a high-end touch smart phone with a 3.2 mega pixel camera and many more promising features to offer.

    blackberry application development

    ReplyDelete
  2. Hello,
    Nice blog i like it
    Take the case of mobile banking for instance. How easily one can access one's account or check balances or transfer funds between accounts, along with the versatility of the banking services offered would decide the effectiveness of mobile application development.

    Mobile applicationdevelopment

    ReplyDelete
  3. i am getting an exception : stackoverflow

    ReplyDelete