views:

2177

answers:

4

Hello,

I've racked my brain for hours over this issue. I have created a main.xml and designed one for the res/layout-land (landscape) format and another one for portrait in res/layout.

When I rotate the emulator (ctrl-F11), my app rotates properly to landscape using the correct main.xml, but a subsequent rotation back to portrait just keeps the landscape mail.xml.

This was done in a 2.0 AVD..

Out of despiration I downloaded the new Sample Code for Multiple Resolutions and had to create a new 2.1 AVD, to my surprise rotation with this app works correctly as expected. So I then decided to try my app on the 2.1 AVD and it works perfectly.

So, is this a Bug in a 2.0 AVD or is there something special I need to be doing for < 2.1 SDK versions?

This is driving me crazy because no where did anyone mention this issue.

Thanks in advance

A: 

Unless you specify

<activity android:name="MainActivity" android:configChanges="orientation">

In your manifest, I think your app should automatically select the correct layout.xml. So, seems like a bug in the emulator to me. Anyway, I found that the emulator is buggy in other ways. Ex. it runs the code twice when you change the orientation back.

PHP_Jedi
A: 

Yes, the emulator is a bit buggy when it comes to orientation changes. I haven't experienced this specific problem, but it does sometimes do strange things. However this definitely isn't an issue with < 2.1 SDKs, on a physical phone at least, because I'm still stuck with v1.5 on my Hero and it properly handles orientation changes by picking the right layout folder to get the xml files from.

Steve H
A: 

I've only done 2.1 development, but another thought I just had would be to try CTRL-F12 (Switch to NEXT layout orientation) instead of CTRL-F11 (Switch to PREVIOUS layout orientation () and see if anything changes. This is from Controlling the Emulator.

Also, there are a number of lifecycle methods you could override to monitor what is happening behind the scenes. That might let you know if there's a bug in the emulator.

We've some basic examples at:

http://www.androidref.com/index1.html#Orientation

Good luck.

Jay

AndroidRef.com