Question

I'm training to change the screenOrientation in manifest with constant values via resources. This is an activity of my manifest:

<activity
    android:name="it.wrapmobile.parcosigurta.NavActivity"
    android:label="@string/app_name"
    android:screenOrientation="@integer/orientation" >
</activity>

i want to change my screenOrientation with this constants http://developer.android.com/reference/android/R.attr.html#screenOrientation , 10inch landscape, 7inch landscape, smartphonne portrait so i created resources xml in 3 different directory:

values/integer.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="orientation">1</integer>
</resources>

values-large/integer.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="orientation">0</integer>
</resources>

values-sw600dp/integer.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="orientation">0</integer>
</resources>

But in all devices the app is always in portrait. What i wrong? Thank you for you help.

M

Was it helpful?

Solution

You could detect the screen size and set the orientation programmatically. Here is an example:

public static void setActivityScreenOrientation(Activity act)
{
    boolean isTablet = false;

    if ((act.getResources().getConfiguration().screenLayout 
            & android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK) == android.content.res.Configuration.SCREENLAYOUT_SIZE_LARGE)
    {
        isTablet = true;
    }

    if ((act.getResources().getConfiguration().screenLayout 
            & android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK) == android.content.res.Configuration.SCREENLAYOUT_SIZE_XLARGE)
    {
        isTablet = true;
    }


    if (isTablet)
    {
        act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }else
    {
        act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top