Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static float getDipByPix(Context context, int Pix) { float scale = context.getResources().getDisplayMetrics().density; return Pix / scale; } }