Java tutorial
//package com.java2s; import android.content.res.Resources; import android.util.TypedValue; public class Main { public static int dpToPx(Resources res, int dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.getDisplayMetrics()); } public static float dpToPx(Resources res, float dp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.getDisplayMetrics()); } }