Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.TypedValue; public class Main { public static float dpToPx(Context context, float dp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()) + 0.5f; } }