title: Vertically centering a view in Android
body: <p>I'm trying to center a <code>View</code> vertically on screen with the following layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;
      &lt;EditText 
          android:text="example text"  
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>However it doesn't work. The <code>EditText</code> is still at the top of the screen. Can someone explain what I'm doing wrong here?</p>
  
  <p><strong>NOTE:</strong> if I add <code>center_horizontal</code> to the <code>layout_gravity</code> attribute then it centers it horizontally, but still does not center vertically.</p>
  
  <p><strong>UPDATE:</strong> using <code>android:gravity="center_vertical"</code> on the parent worked. I still don't understand why <code>android:layout_gravity="center_vertical"</code> on the child didn't work.</p>