 <p>The logical <a href="http://developer.android.com/reference/android/util/DisplayMetrics.html#density" rel="nofollow">density</a> of the display is given in the <code>DisplayMetrics</code> class, and can be retrieved with,</p> <pre><code>getResources().getDisplayMetrics().density </code></pre> <p>Thus, to convert <code>dp</code> to <code>px</code>, you would do,</p> <pre><code>int density = getResources().getDisplayMetrics().density; int px = (int) (dp * density); </code></pre> <p>To convert <code>px</code> to <code>dp</code>, just perform the inverse operation,</p> <pre><code>int dp = px/density; </code></pre>