嗨,伙计们,我正在为平板电脑和移动设备开发一个应用程序,直到现在所有的事情对我来说都是好的。这是我的问题,我不能得到三星Galaxy Tab的高度和宽度?
发布于 2011-10-28 15:03:02
如果需要大小分类--“小”、“正常”、“大”、“xlarge”--请使用Configuration类:
Configuration config = getResources().getConfiguration();
int size = config.screenLayout & config.SCREENLAYOUT_SIZE_MASK;
if (size == config.SCREENLAYOUT_SIZE_SMALL)
{
// use special layout for small screens
}如果需要检查方向,则可以使用:
public int getScreenOrientation()
{
Display getOrient = getWindowManager().getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
if(getOrient.getWidth() == getOrient.getHeight()) {
orientation = Configuration.ORIENTATION_SQUARE;
} else {
if(getOrient.getWidth() < getOrient.getHeight()){
orientation = Configuration.ORIENTATION_PORTRAIT;
} else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
}我不太明白,为什么您需要检查屏幕大小,因为如果您在不同的布局文件夹中添加布局,那么Android会根据屏幕大小自动选择最合适的。
发布于 2011-10-28 12:19:59
试试这个:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
String strScreenSize = "The Android Screen is: "
+ dm.widthPixels
+ " x "
+ dm.heightPixels;发布于 2011-10-28 12:28:29
有几个网站可以获取这类信息,而不必编写脚本。例如http://www.screenresolution.org/
https://stackoverflow.com/questions/7929056
复制相似问题