Here you can find the source of dip2Px(Context context, float dipValue)
public static int dip2Px(Context context, float dipValue)
//package com.java2s; import android.content.Context; public class Main { public static int dip2Px(Context context, float dipValue) { /**//from www.ja v a 2s . c o m * return * Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, * value, context.getResources().getDisplayMetrics())); */ final float scale = getDensity(context); return (int) (dipValue * scale + 0.5f); } /** * * @param context * @return */ public static float getDensity(Context context) { return context.getResources().getDisplayMetrics().density; } }