Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int calWidth(Context ctx, int pxValue) { final float density = ctx.getResources().getDisplayMetrics().density; return (int) ((pxValue / 3) * density + 0.5f); } }