public static float convertDpToPixel(float dp,Context context){
  Resources resources=context.getResources();
  DisplayMetrics metrics=resources.getDisplayMetrics();
  float px=dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
  return px;
}

public static float convertDpToPixel ( float dp , Context context ) { Resources resources = context . getResources ( ) ; DisplayMetrics metrics = resources . getDisplayMetrics ( ) ; float px = dp * ( ( float ) metrics . densityDpi / DisplayMetrics . DENSITY_DEFAULT ) ; return px ; }
this method converts dp unit to equivalent pixels , depending on device density .
