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

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