Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int getPixels(float dps, Context context) { float scale = context.getResources().getDisplayMetrics().density; int pixels = (int) (dps * scale + 0.5f); return pixels; } }