Java tutorial
//package com.java2s; import android.util.DisplayMetrics; import android.view.WindowManager; public class Main { public static int convertDpToPixels(WindowManager windowManager, float dp) { DisplayMetrics metrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(metrics); float logicalDensity = metrics.density; return (int) (dp * logicalDensity + 0.5); } }