Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; public class Main { public static int getPixelsFromDp(Context c, int dp) { final float scale = c.getResources().getDisplayMetrics().density; int pixels = (int) (dp * scale + 0.5f); return pixels; } }