Java tutorial
//package com.java2s; import android.app.Activity; import android.util.DisplayMetrics; public class Main { public static float getScreenWidthDp(Activity act) { final DisplayMetrics displayMetrics = new DisplayMetrics(); act.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); float midu = (float) displayMetrics.densityDpi; return displayMetrics.widthPixels / (midu / 160); } }