How to obtain screen width, height, and Status Bar Height
// Obtain the screen width public static int getScreenWidth (Context context) {WindowManager wm = (WindowManager) context. getSystemService (Context. WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics (); wm. getdefadisplay display (). getMetrics (outMetrics); return outMetrics. widthPixels;}/*** obtain screen height ** @ param context * @ return */public static int getScreenHeight (Context context) {WindowManager wm = (WindowManager) context. getSystemService (Context. WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics (); wm. getdefadisplay display (). getMetrics (outMetrics); return outMetrics. heightPixels;}/*** get the height of the status bar ** @ param context * @ return */public static int getStatusHeight (Context context) {int statusHeight =-1; try {Class
Clazz = Class. forName ("com. android. internal. r$ dimen "); Object object = clazz. newInstance (); int height = Integer. parseInt (clazz. getField ("status_bar_height "). get (object ). toString (); statusHeight = context. getResources (). getDimensionPixelSize (height);} catch (Exception e) {e. printStackTrace ();} return statusHeight ;}