0

i'm using the getrotation function to detect the initial rotation of a screen when my activity is created. But when i used to logged out what returns this function, i mentioned that on my P1000, when rotation = 1 or 3, this means my tablet is in landscape. But on my 10.1 tab, when rotation = 0 or 2, this means my tablet is in landscape. This is causing me a problem in the background image usage replacement. This is my code :

HomeBackground = (ImageView) findViewById(R.id.home_background);
    Display display = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();

        if (rotation == 1 || rotation == 3) {
        HomeBackground.setBackgroundResource(R.drawable.home_bg_landscape);
    } else {
        HomeBackground.setBackgroundResource(R.drawable.home_bg_portrait);
    }

So whats the solution to detect the initial rotation of a screen using another method? or what is my bug? Thank you.

Anthony
  • 189
  • 1
  • 3
  • 16

1 Answers1

3

From the documentation for Display.getRotation():

Returns the rotation of the screen from its "natural" orientation.

The natural orientation of the Galaxy Tab 10.1 is landscape, and I'm assuming for the other device it's portrait.

This answer might help in determining what the default orientation is

Community
  • 1
  • 1
noisecapella
  • 814
  • 7
  • 17
  • So whats the solution to detect the initial rotation of the screen when the user launches the app, not the "natural" orientation? – Anthony Oct 18 '12 at 11:36
  • [link](http://stackoverflow.com/questions/4553650/how-to-check-device-natural-default-orientation-on-android-i-e-get-landscape) very useful for me. That what i need! Thank you. – Anthony Oct 18 '12 at 12:13