title: What is the correct way to specify dimensions in DIP from Java code?
body: <p>I found that it is possible to set dimensions of my interface elements in XML layouts using DIPs as in following fragment: </p>
  
  <pre><code>android:layout_width="10dip"
  </code></pre>
  
  <p>But all Java interface takes integer as arguments and there is no way to specify dimensions in DIPs. What is the correct way to calculate this?</p>
  
  <p>I figured that I have to use property density of <code>DisplayMetrics</code> class but is this a correct way? </p>
  
  <p>May I rely on this formula being always correct?</p>
  
  <blockquote>
    <p>pixels * DisplayMetrics.density = dip </p>
  </blockquote>
  
  <p>Is there a utility function for the conversion somewhere in Android?</p>