0

I am setting the orientation with setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE)

However when I check for the orientation before setting this up using Activity.getResources().getConfiguration().orientation I am getting value 1 which is potrait.

Then I set the orientation with the code. Still I am getting the value 1, also the android system is looking in Layout folder(potrait) for the layout rather than layout-large-land. So conclusion is, How to force set the orientation to Landscape?

Kannan_SJD
  • 1,022
  • 2
  • 13
  • 32

2 Answers2

2

You can force set orientation in AndroidManifest.xml for Activity:

<activity
    android:name="<name_of_your_activity>"
    android:screenOrientation="landscape"
    ...

Update Take a look at this question.

Community
  • 1
  • 1
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • Actually I want to set Potrait orientation for Phones and Landscape for Tablets. So I cannot set the orientation through Manifest – Kannan_SJD Nov 11 '16 at 11:42
0

create bool.xml in values

<resources>
    <bool name="isTablet">false</bool>
</resources>

create another bool.xml in values-sw600dp

<resources>
    <bool name="isTablet">true</bool>
</resources>

then in your activity

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Rajesh Gosemath
  • 1,812
  • 1
  • 17
  • 31