更改与价值观清单screenOrientation [英] Change manifest screenOrientation with values

查看:168
本文介绍了更改与价值观清单screenOrientation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过训练资源,以改变screenOrientation清单中的恒定值。这是我表现的活动:

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>

我要改变我的screenOrientation这个常数的http://开发商.android.com /参考/安卓/ R.attr.html#screenOrientation ,10寸景观,7寸风景,人像smartphonne所以我创建的资源XML在3个不同的目录:

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:

值/ integer.xml

values/integer.xml

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

价值观大/ integer.xml

values-large/integer.xml

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

价值观sw600dp / integer.xml

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

推荐答案

您可以检测屏幕尺寸和编程设置的方向。
下面是一个例子:

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);
    }
}

希望它帮助。

这篇关于更改与价值观清单screenOrientation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆