Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.graphics.Point; import android.view.Display; import android.view.WindowManager; public class Main { /** * Getter for the screen width in pixels. * * @param context a reference to the context. * @return the screen width in pixels. */ public static int getScreenWidth(Context context) { WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point size = new Point(); display.getSize(size); return size.x; } }