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