title: Android Convert Px to Dp (Video Aspect Ratio)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4605527/converting-pixels-to-dp-in-android">converting pixels to dp in android</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to convert pixels to dp.  What is the formula?</p>
  
  <p>Lets convert 640 and 480 into dp.  The docs say this </p>
  
  <blockquote>
    <p>The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160)</p>
  </blockquote>
  
  <p>But I don't think that is what I need (and I don't know how to use this).  I guess I just need the forumla.  I have the code ready:</p>
  
  <pre><code>DisplayMetrics metrics = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(metrics);
  
      switch(metrics.densityDpi)
      {
           case DisplayMetrics.DENSITY_LOW:
           int sixForty = ?
           int fourEighty = ?
           break;
  
           case DisplayMetrics.DENSITY_MEDIUM:
           int sixForty = ?
           int fourEighty = ?
           break;
  
           case DisplayMetrics.DENSITY_HIGH:
           int sixForty = ?
           int fourEighty = ?
           break;
      }
  </code></pre>