title: Android: How to set XML dimen variables programatically
body: <p>In my layout XML files, I reference a lot of parameters through a separate files called <code>dimens.xml</code>.</p>
  
  <p>For example, <code>dimens.xml</code> contains parameters like these:</p>
  
  <pre><code>&lt;dimen name="textSize_normal"&gt;20dp&lt;/dimen&gt;
  &lt;dimen name="buttonTextSize_normal"&gt;15dp&lt;/dimen&gt;
  &lt;dimen name="editTextSize_normal"&gt;17dp&lt;/dimen&gt;
  &lt;dimen name="buttonHeight_normal"&gt;37dp&lt;/dimen&gt;
  &lt;dimen name="margin_normal"&gt;5dp&lt;/dimen&gt;
  </code></pre>
  
  <p>And in my <code>main.xml</code>, for example, I would set the text size for a <code>TextView</code> by doing something like this:</p>
  
  <pre><code>android:textSize="@dimen/editTextSize_normal"
  </code></pre>
  
  <p>It works great.</p>
  
  <p>Now, my questions is, is it possible to set the values for the <code>dimen</code> variables in my <code>dimen.xml</code> file programmatically from my main activity? What I am trying to do is fetch the screen size, and set, for example, the <code>textSize</code> based on a fraction of the height of the screen so that it is easily adaptable to any screen size. I have all that figured out, I just need your help to figure out how to set the <code>dimen</code> variables in my code.</p>