判断屏幕尺寸

// support from API 4
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;
	default:
		break;
}

有一点要注意,必须在AndroidManifest.xml里加上下面的声明
<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

你可能感兴趣的:(android,screensize,mdpi,hdpi,xhdpi)