Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.util.TypedValue; public class Main { public static float dip2pxF(Context context, float dp) { return convertUnitToPixel(context, TypedValue.COMPLEX_UNIT_DIP, dp); } private static float convertUnitToPixel(Context context, int unit, float in) { return TypedValue.applyDimension(unit, in, context.getResources().getDisplayMetrics()); } }