Hesam
Hesam

Reputation: 53600

Is it possible to Force mobile to use vertical layout while tablet to use horizontal layout in single app?

I have an application that supports all Android devices.

I want to know is it possible, based on device:

Therefore, application displays vertical on mobile phones (regardless of portrate or landscape mode) and displays horizontal on tablets (regardless of portrate mode or landscape mode)

By use of following lines of code application always displays portrait. Although it works for mobile but doesn't work for tablet.

android:screenOrientation = "portrait"
android:configChanges="keyboard|keyboardHidden|orientation"

I want to force application that uses vertical design if device is phone/phablet or uses horizontal design if device is tablet.

Hope my explanation is clear. Any suggestion would be appreciated. Thanks.

Upvotes: 3

Views: 599

Answers (1)

Emre Koç
Emre Koç

Reputation: 1381

Yes you can know device is tablet or not..

Here is my code..

 if(isTablet(this))
    {
    setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);  
            }

If device is tablet, function will return true

public static boolean isTablet(Context context) {
        return (context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE;   }

Upvotes: 2

Related Questions