Java tutorial
//package com.java2s; //License from project: Apache License import android.content.res.Resources; public class Main { public static int dp2px(final float dpValue) { final float density = Resources.getSystem().getDisplayMetrics().density; return (int) (dpValue * density + 0.5f); } }