Here you can find the source of convertDptoPx(Context context, int dp)
public static int convertDptoPx(Context context, int dp)
//package com.java2s; import android.content.Context; public class Main { public static int convertDptoPx(Context context, int dp) { float scale = context.getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); }//from w ww .j a v a 2s . co m }