Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; public class Main { public static final int getHeightInDp(Context context) { final float height = context.getResources().getDisplayMetrics().heightPixels; int heightInDp = px2dip(context, height); return heightInDp; } public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } }