Here you can find the source of convertDIP2PX(Context context, float dip)
public static int convertDIP2PX(Context context, float dip)
//package com.java2s; import android.content.Context; import android.content.res.Resources; public class Main { public static int convertDIP2PX(Context context, float dip) { Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; resources = null;/*from w ww .j ava 2 s . co m*/ return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1)); } }