// 获取屏幕的宽度、高度
Display defDip = getWindowManager().getDefaultDisplay();
int disWidth = defDip.getWidth();
int disHeight = defDip.getHeight();
Log.i("TAG", "disWidth:" + disWidth + ",disHeight:" + disHeight);
//获取屏幕分辨率
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
float horiDpi = dm.xdpi; // 屏幕的水平分辨率
float vertDpi = dm.ydpi; // 屏幕的垂直分辨率
// 获得android系统对于目前的屏幕分辨率的分类:
int screenSizeClass = dm.densityDpi;
Log.i("TAG", "screenSizeClass..." + screenSizeClass);
switch (screenSizeClass) {
case DisplayMetrics.DENSITY_LOW: // 屏幕属于低分辨率,运行对应的代码
Log.i("TAG", "低分辨率");
break;
case DisplayMetrics.DENSITY_MEDIUM: // 中分辨率
Log.i("TAG", "中分辨率");
break;
case DisplayMetrics.DENSITY_HIGH: // 高分辨率
Log.i("TAG", "高分辨率");
break;
case DisplayMetrics.DENSITY_XHIGH: // 超高分辨率
Log.i("TAG", "超高分辨率");
break;
case DisplayMetrics.DENSITY_XXHIGH:
Log.i("TAG", "超超高分辨率");
break;
default:
break;
}
// 判断屏幕尺寸
final int screenSize = getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK;
switch (screenSize) {
case Configuration.SCREENLAYOUT_SIZE_SMALL:
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
break;
case Configuration.SCREENLAYOUT_SIZE_LARGE:
break;
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
// support from API 9
break;
case Configuration.SCREENLAYOUT_SIZE_MASK:
break;
case Configuration.SCREENLAYOUT_SIZE_UNDEFINED:
break;
default:
break;
}
1 有一点要注意,必须在AndroidManifest.xml里加上下面的声明
2
3 <supports-screens
4 android:largeScreens="true"
5 android:normalScreens="true"
6 android:resizeable="true"
7 android:smallScreens="true"
8 android:xlargeScreens="true" />
http://wake.hiapk.com/share/design/130417/1422786.html