Java tutorial
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; public class Main { /** * Converts a size value in dp scale into pixel scale. */ public static int dpToPx(Context context, int dp) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return px; } }