Reputation: 21076
In my onCreate method, I'd like to detect the orientation and set an appropriate background image.
I can get the orientation like so:
Display dis = getWindowManager().getDefaultDisplay();
int orientation = dis.getOrientation();
I've tested this on both the Galaxy S and the Moment.
When I am in portrait mode, this returns a value of 0. When I am in landscape mode, this returns a value of 1.
However, the define Configuration.ORIENTATION_LANDSCAPE has a value of 2 and the define Configuration.ORIENTATION_PORTRAIT has a value of 1.
So, when I turn the phone to landscape mode, it gives me Configuration.ORIENTATION_PORTRAIT. And when I turn the phone to portrait mode, it gives me Configuration.ORIENTATION_UNDEFINED.
What is going on???
I'm using API level 7
Upvotes: 0
Views: 515
Reputation: 134714
One thing you could do is just put the landscape drawable into a /drawable-land/
folder, and Android will pull it automatically depending on the orientation. Rather than relying on that, though, you would be better off to make a landscape version of the layout under /layout-land/
that has the alternate version as its background.
Upvotes: 1