Snake
Snake

Reputation: 14648

Setting the orientation to be landscape for large screens

I know that in order for me to force the app to be in a certain orientation then I do this in the manifest file for each activity: android:screenOrientation="portrait" My question is, if I want to set the orientation to landscape ONLY for large screens, then how can I do it? What I know is that there are layout folders specific for each screen size but what about manifest file? It is common for all screen sizes. Any suggestions? Thanks

Upvotes: 1

Views: 776

Answers (4)

HjK
HjK

Reputation: 3513

Check for the device that is being used through the code. A sample code for device checking is:

     context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)==4

or

       Build.VERSION.SDK_INT >=11

This code is basically for checkinh if its honeycomb tabor not. After checking this set the orientation through code:

          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Upvotes: 1

Rahul
Rahul

Reputation: 757

you can set orientation in menifest file for particular screen

Upvotes: 0

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

Use the below code do so

if((getApplicationContext().getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

}

Upvotes: 0

5hssba
5hssba

Reputation: 8079

Put this in your onCreate of activities..

if ((getResources().getConfiguration().screenLayout & 
Configuration.SCREENLAYOUT_SIZE_MASK) == 
    Configuration.SCREENLAYOUT_SIZE_LARGE) {
   setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

}

Upvotes: 0

Related Questions