【发布时间】:2012-08-21 16:38:39
【问题描述】:
有没有办法让 Android Manifest 因屏幕尺寸而异?如果设备是平板电脑(即 xlarge 屏幕尺寸),我希望 android:configChanges 不包括“方向”
此外,我希望 android:screenOrientation 根据使用的设备而有所不同。有什么建议吗?
【问题讨论】:
标签: android manifest tablet screen-size
有没有办法让 Android Manifest 因屏幕尺寸而异?如果设备是平板电脑(即 xlarge 屏幕尺寸),我希望 android:configChanges 不包括“方向”
此外,我希望 android:screenOrientation 根据使用的设备而有所不同。有什么建议吗?
【问题讨论】:
标签: android manifest tablet screen-size
我不知道如何在 AndroidManifest.xml 中执行如此复杂的操作,但是您可以通过 Activity.setRequestedOrientation() 方法以编程方式执行此操作。将其包装在实用程序类中并相应地查询您的环境很容易。一个警告虽然 - 如果调用此方法确实导致方向更改,您的 Activity 的 onCreate() 将被第二次调用。如果您选择走这条路线,另一件事可能会派上用场,如果以下计算结果为真:
if((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {...}
然后你在平板设备上,或者至少你的布局是从 layout-large 加载的(如果你有的话)。综上所述,以下内容会将平板电脑锁定为横向模式,将手机锁定为纵向模式:
if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
return true;
} else if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
return false;
} else if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
return false;
} else {
// Assume that all other ratings are tablets or possibly even larger devices; there is an
// extra large spec however it is only available OS versions 3.x and above so there is no clean way to query for this state.
return true;
}
【讨论】:
请看看这个 ………… 支持屏幕 android:resizeable=["true"| "假"] android:smallScreens=["真" | "假"] android:normalScreens=["真" | "假"] android:largeScreens=["真" | "假"] android:xlargeScreens=["真" | "假"] android:anyDensity=["真" | “假”] android:requiresSmallestWidthDp="integer" android:compatibleWidthLimitDp="integer" android:largestWidthLimitDp="integer ………………………………………………………………………… 它将是处理你的屏幕
【讨论】: