Here you can find the source of convertDpToPixel(float dp, Context context)
public static float convertDpToPixel(float dp, Context context)
//package com.java2s; import android.content.Context; import android.content.res.Resources; import android.util.DisplayMetrics; public class Main { public static float convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return px; }//from w w w. j av a 2 s.c om }