我正在训练通过资源以恒定值更改清单中的 screenOrientation 。这是我的清单的一项活动:
<activity
android:name="it.wrapmobile.parcosigurta.NavActivity"
android:label="@string/app_name"
android:screenOrientation="@integer/orientation" >
</activity>
我想用这个常量改变我的 screenOrientationhttp://developer.android.com/reference/android/R.attr.html#screenOrientation http://developer.android.com/reference/android/R.attr.html#screenOrientation,10英寸横向,7英寸横向,智能手机纵向,所以我在3个不同的目录中创建了资源xml:
值/integer.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="orientation">1</integer>
</resources>
值-大/integer.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="orientation">0</integer>
</resources>
值-sw600dp/integer.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="orientation">0</integer>
</resources>
但在所有设备中,该应用程序始终是纵向的。我错了什么?
谢谢你的帮助。
M
您可以检测屏幕尺寸并以编程方式设置方向。
这是一个例子:
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);
}
}
希望能帮助到你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)