Here you can find the source of dip2px(Context context, float dpvalue)
public static int dip2px(Context context, float dpvalue)
//package com.java2s; //License from project: Apache License import android.content.Context; public class Main { public static int dip2px(Context context, float dpvalue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpvalue * scale + 0.5f); }// ww w . ja v a 2 s .c om }