3

I am trying to use different layouts for different screen resolution

and I have successfully done it.

My problem is, I need only Landscape orientation for Large and Xlarge Layouts

and Portrait for Normal and Small. I am using only Layout-large-land and Layout-xlarge-land in my

res folder, it takes portrait also.Similarly for Normal and small it takes portrait along with

landscape. So How do i do that programatically set the orientation according to screen resolution

in java files??

Can someone help me??

DevAndro
  • 205
  • 1
  • 6
  • 18
  • 1
    Try looking at the answer [here](http://stackoverflow.com/questions/6466481/how-to-get-the-density-of-a-screen) and then use that info to set the orientation based on [this](http://stackoverflow.com/questions/4820392/orientation-in-android) – TronicZomB Mar 18 '13 at 14:20
  • Actually you say that you want to set the orientation based on screen resolution but you use the layout folder names that are for screen sizes. These are two different values. For example, the Nexus is a 4 inch screen putting it in the normal bucket but its resolution puts it in the high density (or extra high density, can't remember) bucket. You may want to clarify what it is you want exactly. – TronicZomB Mar 18 '13 at 14:25

1 Answers1

5

you need to call this in your Activity's onCreate Method:

if ((this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)  <= Configuration.SCREENLAYOUT_SIZE_NORMAL) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
Thommy
  • 5,070
  • 2
  • 28
  • 51