/** 获取手机的屏幕宽 */
public static int getSW(Context context) {
int sw;
WindowManager wm = (WindowManager) context
.getSystemService(Context. WINDOW_SERVICE);
if (context.getResources().getConfiguration(). orientation == Configuration.ORIENTATION_PORTRAIT ) {
sw = wm.getDefaultDisplay(). getWidth(); // 当屏幕是竖屏
} else {
//sw = wm.getDefaultDisplay().getHeight();
sw = wm.getDefaultDisplay(). getWidth(); // 当屏幕是横屏
}
return sw;
}
/** 获取手机的屏幕高 */
public static int getSH(Context context) {
int sh;
WindowManager wm = (WindowManager) context
.getSystemService(Context. WINDOW_SERVICE);
if (context.getResources().getConfiguration(). orientation == Configuration.ORIENTATION_PORTRAIT ) {
sh = wm. getDefaultDisplay().getHeight(); // 当屏幕是竖屏
} else {
sh = wm.getDefaultDisplay(). getHeight(); // 当屏幕是横屏
//sh = wm.getDefaultDisplay().getWidth();
}
return sh;
}
Log日志: