Java tutorial
//package com.java2s; import android.content.res.Resources; import android.util.DisplayMetrics; public class Main { /** * Returns the number of pixels corresponding to the passed density pixels */ public static int convertDpToPixels(int dp) { DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); return (int) (dp * metrics.density + 0.5f); } }