title: Android: using predefined dimens parameters in programmatic layout
body: <p>I want to use some predefined dimensions from my dimens.xml file in my programmatic layout. </p>
  
  <p>So for instance, in my dimens.xml file I have:</p>
  
  <pre><code>&lt;dimen name="margin1"&gt;40dip&lt;/dimen&gt;
  &lt;dimen name="margin2"&gt;40dip&lt;/dimen&gt;
  </code></pre>
  
  <p>And then in my programmatic textview I have:</p>
  
  <pre><code>RelativeLayout.LayoutParams lpMargin = new RelativeLayout.LayoutParams( R.dimen.margin1, R.dimen.margin2);
  </code></pre>
  
  <p>Applying the layout parameter to my textview results in an enormous view.</p>
  
  <p>I already found the problem. If I print out:</p>
  
  <pre><code>Log.e("Metrics", "margin width = " +  String.valueOf(R.dimen.margin1));
  </code></pre>
  
  <p>...it gives an enormous value: <code>margin width = 2131034112</code>. The thing that's messing it up is the units, "dip". </p>
  
  <p>So my question is: what's the correct way to specify dimensions without units for calling programmatically? If that's not possible, can I alter R.dimen.margin1 so I can use it as a programmatic layout parameter?</p>
  
  <p>EDIT: It wasn't the units messing it up -- it's returning the internal ID! (As <em>ianhanniballake</em> says below, I needed to call with <code>getResources().getDimension(R.dimen.margin1)</code>).</p>