我正在培训如何通过资源使用常量值更改清单中的screenOrientation。这是我清单上的一项活动:
<activity
android:name="it.wrapmobile.parcosigurta.NavActivity"
android:label="@string/app_name"
android:screenOrientation="@integer/orientation" >
</activity>我想用常量screenOrientation更改http://developer.android.com/reference/android/R.attr.html#screenOrientation、10英寸景观、7英寸景观、smartphonne概要,因此我在3个不同的目录中创建了resources:
值/整型
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="orientation">1</integer>
</resources>值-大/整型.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="orientation">0</integer>
</resources>值-sw600dp/intger.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="orientation">0</integer>
</resources>但在所有设备中,应用程序总是在人像中。我做错什么了?谢谢你的帮助。
我
发布于 2014-02-28 21:13:12
您可以通过编程方式检测屏幕大小并设置方向。下面是一个示例:
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);
}
}希望能帮上忙。
https://stackoverflow.com/questions/22104958
复制相似问题