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