title: How to vertically align text in a button with a background drawable?
body: <p>I had a simple button set up with a background image defined like</p>
  
  <pre><code>android:background="?attr/button"
  </code></pre>
  
  <p>where <code>?attr/button</code> was a reference to a simple 9-patch png. Everything worked fine, text in the button was aligned correctly.</p>
  
  <p>Then I needed to have a different background for a pressed state of the button. So I changed that to</p>
  
  <pre><code>android:background="@drawable/state_button"
  </code></pre>
  
  <p>where <code>@drawable/state_button</code> is an xml with the following states</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:state_pressed="true"
          android:drawable="@drawable/button_pressed" /&gt; &lt;!-- pressed --&gt;
      &lt;item android:state_focused="true"
          android:drawable="@drawable/button_pressed" /&gt; &lt;!-- focused --&gt;
      &lt;item android:drawable="@drawable/button" /&gt; &lt;!-- default --&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>And after that I can't align the text properly. If I put <code>android:gravity="center_vertical"</code> the text is drawn about 1/4 of the button height from the top.</p>
  
  <p>I double-checked my 9-patch images, everything seems fine with them. And I also tried having regular pngs for the background, it also doesn't change anything.</p>