Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make it only landscape for tablets and only portrait for phones?

how can it so that when a tablet is running the application, it is forced to run it in landscape and when a phone is running the application, it is forced to run it in portrait? I've managed to force it to run in lets say portrait, but then it run portrait for tablets too... Portrait mode in tablets is ugly :( Thanks

like image 628
Alexandre Hitchcox Avatar asked Apr 14 '12 13:04

Alexandre Hitchcox


2 Answers

Here is my suggestion: First try to determine the type of device using screen dimensions. You could refer to this post. On the second step you can change the screen orientation using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);. There is another post here.

like image 168
Jermin Bazazian Avatar answered Nov 07 '22 04:11

Jermin Bazazian


Just set nosensor parameter for activity in manifest:

    <activity
        android:name=".activity.MyActivity"
        android:configChanges="keyboardHidden|orientation|screenSize" 
        android:screenOrientation="nosensor">

By the way, some tablets may be detected as phones, for example Nexus 7.

like image 42
Alex Kucherenko Avatar answered Nov 07 '22 04:11

Alex Kucherenko