title: Center Editext in a Linear Layout - Android
body: <p>I'm trying to center the editText which you can see in this screen (the one on the black buttons):
  <a href="https://i.stack.imgur.com/Qvm6J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qvm6J.png" alt="enter image description here"></a></p>
  
  <p>This is my code. I set the <strong>android:gravity="center_horizontal"</strong> tag, but as you can see it doesn't works. I do not understand if I need to set it at the center of its linear layout or if I need to pay attention to the external linear layout:</p>
  
  <pre><code>&lt;LinearLayout 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"
      android:background="#FCFCFC"
      android:orientation="vertical"
      android:layout_marginTop="8dp"
      tools:context=".PaintingActivity" &gt;
  
      &lt;!-- Top Buttons --&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="50dp"
          android:layout_gravity="center"
          android:orientation="horizontal" &gt;
  
  
          &lt;ImageButton
              android:id="@+id/draw_btn"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_marginRight="50dp"
              android:contentDescription="@string/brush"
              android:background="@drawable/rounded_corners"
              android:padding="16dp"
              android:layout_marginTop="5dp"
              android:src="@drawable/brush" /&gt;
  
          &lt;ImageButton
              android:id="@+id/erase_btn"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_marginRight="50dp"
              android:contentDescription="@string/erase"
              android:background="@drawable/rounded_corners"
              android:padding="16dp"
              android:layout_marginTop="5dp"
              android:src="@drawable/eraser" /&gt;
  
          &lt;ImageButton
              android:id="@+id/undo_btn"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:contentDescription="Undo"
              android:layout_marginRight="50dp"
              android:background="@drawable/rounded_corners"
              android:padding="16dp"
              android:layout_marginTop="5dp"
              android:src="@drawable/undo" /&gt;
  
          &lt;ImageButton
              android:id="@+id/colorPicker"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_marginTop="5dp"
              android:background="@drawable/rounded_corners"
              android:contentDescription="colorPicker"
              android:padding="16dp"
              android:src="@drawable/palette" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;!-- Custom View --&gt;
  
      &lt;com.example.williamstest.DrawingView
          android:id="@+id/drawing"
          android:layout_width="fill_parent"
          android:layout_height="0dp"
          android:layout_marginBottom="3dp"
          android:layout_marginLeft="5dp"
          android:layout_marginRight="5dp"
          android:layout_marginTop="3dp"
          android:layout_weight="1"
          android:background="#FFFFFFFF" /&gt;
  
      &lt;!-- Menu in basso --&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:orientation="vertical" &gt;
  
          &lt;!-- Top Row --&gt;
  
          &lt;LinearLayout
              android:id="@+id/toprow"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="@dimen/_70sdp"
              android:orientation="horizontal"&gt;
  
              &lt;EditText
                  android:id="@+id/edittitle"
                  android:layout_width="400dp"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="15dip"
                  android:layout_marginBottom="25dip"
                  android:ems="10"
                  android:hint="Inserisci qui il titolo"
                  android:gravity="center_horizontal"
                  android:inputType="textNoSuggestions"
                  android:singleLine="true"/&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;!-- Bottom Row --&gt;
  
          &lt;LinearLayout
              android:id="@+id/bottomrow"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginRight="120dp"
              android:orientation="horizontal"&gt;
  
              &lt;Button
                  android:id="@+id/bb_3"
                  android:layout_width="100dp"
                  android:layout_height="50dp"
                  android:layout_marginLeft="120dp"
                  android:layout_marginBottom="10dp"
                  android:background="@drawable/button_bg"
                  android:text="Indietro"
                  android:textColor="#FFFFFF" /&gt;
  
              &lt;Button
                  android:id="@+id/bb_2"
                  android:layout_width="100dp"
                  android:layout_height="50dp"
                  android:layout_marginLeft="120dp"
                  android:layout_marginBottom="10dp"
                  android:layout_weight="1"
                  android:background="@drawable/button_bg"
                  android:text="Avanti"
                  android:textColor="#FFFFFF" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>