Java tutorial
//package com.java2s; import android.app.Activity; import android.util.DisplayMetrics; public class Main { /** * Dp to pixels. * * @param context the context * @param dp the dp * @return the int */ public static int dpToPixels(Activity context, int dp) { DisplayMetrics metrics = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay().getMetrics(metrics); return (int) ((dp * metrics.density) + 0.5); } }