0

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

Andrew
  • 20,756
  • 32
  • 99
  • 177
  • possible duplicate of [Check orientation on Android phone](http://stackoverflow.com/questions/2795833/check-orientation-on-android-phone) – Cheryl Simon Dec 03 '10 at 22:38

2 Answers2

1

Look at the answers in Check orientation on Android phone

Community
  • 1
  • 1
Mikpa
  • 1,912
  • 15
  • 20
1

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.

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274