title: getDisplayMetrics().density vs dp
body: <p>Do these two do the same in terms of mathematics? Do they produce the same result?</p>
  
  <p>Java:</p>
  
  <pre><code>pixel=10;
  margin=px * getResources().getDisplayMetrics().density;
  layout_param.topMargin=margin;
  </code></pre>
  
  <p>XML:</p>
  
  <p><code>android:layout_marginTop="10dp"</code></p>