Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.graphics.Point; import android.view.Display; import android.view.WindowManager; public class Main { private static Point screenSize; public static int getWindowWidth(Context context) { if (screenSize == null) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); screenSize = new Point(); display.getSize(screenSize); } if (screenSize != null) return screenSize.x; else return 0; } }