Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; public class Main { public static int dp2px(float dp, Context context) { return (int) (dp * getDisplayDensity(context) + 0.5f); } public static float getDisplayDensity(Context context) { return context.getResources().getDisplayMetrics().density; } }