更新时间:2023-02-27 10:41:48
您可以检测屏幕尺寸和编程设置的方向。
下面是一个例子:
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);
}
}
希望它帮助。