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