title: How to center a button with margin in android layout?
body: <p>In the android layout I want to have two rows: </p>
  
  <ol>
  <li><p>In the first row ONE button centered in the middle of the screen on top. Ledt and right to it some space. </p></li>
  <li><p>A row of other buttons below that firs button with some distance. </p></li>
  </ol>
  
  <p>Below is the code I tried to use. For the first <code>LinearLayout</code> I tried <code>android:layout_gravity="center_vertical"</code> as well as <code>android:layout_gravity="center_horizontal"</code>, and I put a line <code>android:layout_marginBottom="10dp"</code> in the <code>LinearLayout</code> <em>and</em> the first <code>Button</code>. I have used <a href="https://stackoverflow.com/questions/1264465/how-can-i-create-2-rows-of-buttons-in-android-layout-xml-file">this answer</a> as a template.</p>
  
  <p>However, there is no vertical space between the buttons in the first row and the second row, and the first button in the first row (on top) is on the <em>left</em> side of the screen. I thought I did put the right attributes in the <code>xml</code> file, but probably it is much more complicated. As always...</p>
  
  <p>Here is the code of the full <code>xml</code>:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity" &gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical"
          android:layout_marginBottom="10dp"
          &gt;
  
          &lt;Button
              android:id="@+id/list_ok"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginBottom="10dp"
              android:text="@string/ok"
              android:onClick="buttonEndStat"
              &gt;
          &lt;/Button&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:id="@+id/header_list"
          android:layout_marginTop="36dp"
          &gt;
  
  
          &lt;Button
              android:id="@+id/listname"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.225"
              android:layout_below="@id/list_ok"
              android:text="@string/headerName"&gt;
          &lt;/Button&gt;
          &lt;Button
              android:id="@+id/listok"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.1"
              android:text="@string/headerOK"&gt;
          &lt;/Button&gt;
          &lt;Button
              android:id="@+id/listnok"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.1"
              android:text="@string/headerNOK"&gt;
          &lt;/Button&gt;
          &lt;Button
              android:id="@+id/listhist"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.2"
              android:text="@string/headerHist"&gt;
          &lt;/Button&gt;
          &lt;Button
              android:id="@+id/listprandom"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.15"
              android:text="@string/headerP"&gt;
          &lt;/Button&gt;
          &lt;Button
              android:id="@+id/listphist"
              android:layout_width="0px"
              android:layout_height="wrap_content"
              android:layout_weight="0.075"
              android:text="@string/headerH"&gt;
          &lt;/Button&gt;
          &lt;Button
              android:id="@+id/listptot"
              android:layout_width="0px"
              android:layout_height="wrap_content"
              android:layout_weight="0.075"
              android:text="@string/headerProb"&gt;
          &lt;/Button&gt;
          &lt;Button
              android:id="@+id/listproc"
              android:layout_width="0px"
              android:layout_height="wrap_content"
              android:layout_weight="0.075"
              android:text="%"&gt;
          &lt;/Button&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;ListView
          android:id="@+id/listview1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="5dp"
          android:layout_below="@id/header_list"
          &gt;
      &lt;/ListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>