[英]How to determine screen orientation and size bucket programatically in Android 2.3.3 SDK
My application is supposed decide whether to display in dual-pane or single-pane using the following logic: 我的应用程序应该使用以下逻辑决定是在双窗格还是单窗格中显示:
I am developing for Android 2.3.3 SDK, so the nice features of Android 3.0 SDK are not applicable here. 我正在开发Android 2.3.3 SDK,所以Android 3.0 SDK的不错功能在这里不适用。 The function I have developed below always returns SINGLE-PANE for all screen sizes and orientation combinations.
我在下面开发的功能总是为所有屏幕尺寸和方向组合返回SINGLE-PANE。 What could be going wrong here?
这可能会出错?
/**
* Determine if a dual pane is appropriate.
*
* @param null
* @return boolean
*/
public boolean isDualPane() {
boolean dualPane = false;
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
dualPane = true;
}
}
Log.d("ORIANTATION", (dualPane) ? "DUAL PANE" : "SINGLE PANE");
return dualPane;
}
I have found the answer. 我找到了答案。 There is nothing wrong with the above function!
上面的功能没有错! The problem was with the configuration of my emulator.
问题在于我的模拟器的配置。 I created a WVGA800 device and left the LCD density at 240 instead of 160. That makes it a normal size and not a large size.
我创建了一个WVGA800设备,并将LCD密度保持在240而不是160.这使它成为正常尺寸而不是大尺寸。 So the statememnt
Configuration.SCREENLAYOUT_SIZE_LARGE
always evaluated to 2 instead of 3. So the if statement
failed each time. 因此,statememnt
Configuration.SCREENLAYOUT_SIZE_LARGE
始终计算为2而不是3.因此if statement
每次都失败。 It works fine now. 它现在工作正常。
One more thing, this : 还有一点, 这个 :
if ((getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
dualPane = true;
}
needs to be changed to: 需要改为:
if ((getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) {
dualPane = true;
}
In order to cater for XLARGE screens as well. 为了满足XLARGE屏幕的需求。
I dont know much about dual pane, but I suggest you control the configuration Small-Normal-Large-Xlarge layout from XML. 我不太了解双窗格,但我建议您从XML控制配置Small-Normal-Large-Xlarge布局。
Example : 示例:
It maybe Helping you. 它可能会帮助你。 :)
:)
Refference : Screen size 参考: 屏幕尺寸
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.