title: Centering a button in a linear layout
body: <p>Using gravity on LinearLayout centers the button correctly:</p>
  
  <pre><code>    &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:gravity="center"&gt;
  
          &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/new"
          android:paddingLeft="40dp"
          android:paddingRight="40dp"/&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>But using layout_gravity=center on the Button only centers the button horizontally and not vertically, why?</p>
  
  <pre><code>        &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"&gt;
  
              &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="TEST"
              android:paddingLeft="40dp"
              android:paddingRight="40dp"
              android:layout_gravity="center"/&gt;
          &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Wq04v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wq04v.png" alt="enter image description here"></a></p>