1

Is there a way to force the tablet to be in landscape mode as default orientation when the user start's my app. Is there a way to do this with theming or something like that, so the user doent see orientation change when he is starting the app?

Note: the same app is (should be) in portrait mode for phones

For now I have a boolean values folder refs.xml(both values and values-large) with different value for tablet and phone, but the user can see that the app is rotating Code:

public static boolean isTablet(Context context) {   
        return (context.getResources().getBoolean(R.bool.isTablet));
    }
Darko Petkovski
  • 3,892
  • 13
  • 53
  • 117
  • In general I wouldn't recommend you do this. Forcing a particular orientation breaks the UX and I'm not the only person to find it very annoying to the point that I don't use apps which do it. Why don't you just create layouts for the different orientations and let the users use their devices the way they want too? – Squonk Sep 03 '14 at 07:43

5 Answers5

3
    if (isTablet(getApplicationContext())) {
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    setContentView(R.layout.yourlayout);



**//this method for check having run in tablet or not??**

     public static boolean isTablet(Context context) {
         return (context.getResources().getConfiguration().screenLayout
                        & Configuration.SCREENLAYOUT_SIZE_MASK)
                        >= Configuration.SCREENLAYOUT_SIZE_LARGE;
     }
Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34
Dakshesh Khatri
  • 639
  • 7
  • 12
1

Landscape does not mean this is tablet. You should put isTablet for tables in XML file stored in res/values-sw600dp instead.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

I think you just need to add screenOrientation in your activity tag in manifest.xml as below :

<activity>
    android:screenOrientation="landscape"
</activity>

And you application will open in landscape mode

Mark Rhodes
  • 10,049
  • 4
  • 48
  • 51
Menma
  • 799
  • 1
  • 9
  • 35
0

You should use android:screenOrientation="landscape" in Manifest file where you define your activities

<activity
            android:name="com.yourpackage.ActivityClassName"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
XtreemDeveloper
  • 1,132
  • 9
  • 14
-1

add below line in your manifest under activity tag...

            android:screenOrientation="landscape"
Bhaskar
  • 911
  • 6
  • 18