Saturday, March 13, 2010

Adapting to sizeChanged

Cell phones with accelerometers may automatically change the screen orientation from portrait to landscape.
If you use LCDUI screens on your application there is nothing to worry.
But if you use Canvas these changes are notified by sizeChanged method.

At my Books application I show text in fullscreen landscape.
The user will need to rotate the handset to read properly.
If the cell phone automatically change the screen orientation the user will not be able to read.

What I had to do is to implement sizeChanged method to check if Sprite rotation is needed or not:

public void sizeChanged (int w, int h) {
if (sprite == null) return;
if (super.getWidth() < super.getHeight()) { // portrait screen
} else {
sprite.setPosition(0, 0);

Related Topics:

No comments: