Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.util.TypedValue; public class Main { /** * Converts density pixels to pixels * * @param context context for getResources() * @param dp desired density pixels * @return converted dp to pixels */ static float dpToPx(Context context, final int dp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); } }