Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.TypedValue; public class Main { static int getPixelForDp(Context context, int displayPixels) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, displayPixels, context.getResources().getDisplayMetrics()); } }