Reputation: 14648
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
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
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
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