【发布时间】:2013-05-10 22:00:17
【问题描述】:
所以,如果我的屏幕尺寸是 mdpi 或 hdpi,我会检查我的 main_activity 类,并根据我需要在我的游戏活动中启动适当的方法。我的数据库中有两个表,其中包含 mdpi 和 hdpi 图像。但我什么也得不到。只有我空白的主要活动。有什么问题?这是我的主要活动:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
if((width>320) && (width<480)){
Intent i = new Intent(MainActivity.this, GameDanska.class);
i.putExtra("myMethod", "nextQuestionMDPI");
startActivity(i);
}
else if((width>480) && (width<720)){
Intent i2 = new Intent(MainActivity.this, GameDanska.class);
i2.putExtra("myMethod", "nextQuestionHDPI");
startActivity(i2);
}
}
【问题讨论】:
-
通过打印宽度值来检查
-
我怀疑 width==0。
-
你检查过你的屏幕分辨率吗?您只允许宽度 321->479 和 481->719。这些都是非常奇怪的决议。例如我的 GNex 有 1280x720,所以完全超出了您允许的范围。
-
我建议您通过执行this, look the answer with a switch 之类的操作来检查设备上的密度,然后开始您想要的活动。
-
我的屏幕是 320X480。我百分百确定。这是宏达魔术。 @Marc B我只检查宽度,而不是高度。我检查只是为了检查它是 mdpi 还是 hdpi,宽度就足够了。