Here you can find the source of formatDipToPx(Context context, float dip)
public static int formatDipToPx(Context context, float dip)
//package com.java2s; import android.app.Activity; import android.content.Context; import android.util.DisplayMetrics; public class Main { public static int formatDipToPx(Context context, float dip) { DisplayMetrics dm = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay() .getMetrics(dm);//from www. j a v a 2 s . co m return (int) Math.ceil(dip * dm.density); } }