title: Android XML defined dimension value yielding unexpected results
body: <p>I have defined a dp dimension in my XML file like so:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;dimen name="custom_button_Margin"&gt;10dp&lt;/dimen&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>The idea being that I use these values to set the padding between elements. This works fine when I use the value in my layout XML file.</p>
  
  <p>Snippet:</p>
  
  <pre><code>&lt;RelativeLayout
      android:id="@+id/mainButtons"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="0.4"
      android:layout_margin = "5dp"
  
      android:gravity="right|bottom"&gt;
      &lt;Button
          android:id="@+id/_7"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/seven"
  
          android:background = "@drawable/custom_button"
          android:typeface="monospace"
          android:textSize="@dimen/custom_button_TextSize"
  
          android:layout_marginRight = "@dimen/custom_button_Margin"
          android:layout_marginBottom = "@dimen/custom_button_Margin"
      /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>The problem lies when I attempt to get this value programmatically. I expect to get a value that has been scaled to match the screen density. Then all I would do is follow the formula found <a href="http://developer.android.com/guide/practices/screens_support.html#compatibility-examples" rel="nofollow">here</a> (the page is quite long look for <strong>Converting dp units to pixel units</strong>)</p>
  
  <p>I wrapped the formula in a function that retrieves the value defined in the file, and scales it to pixels.</p>
  
  <pre><code>private int get_custom_button_PadV()
      {
      final float scale = getResources().getDisplayMetrics().density;
  
      return (int) (R.dimen.custom_button_Margin * scale + 0.5f);
      }
  </code></pre>
  
  <p>When I watch the code, I see the following values</p>
  
  <pre><code>scale = 1.0
  R.dimen.custom_button_Margin = 2131099650
  </code></pre>
  
  <p>I can't figure out why the custom_button_Margin value is so large...I would expect that with a scale of 1.0, that there would be a value of 10. What am I missing?</p>