title: Custom Alert dialog not centered vertically on Android
body: <p>I made a custom alert dialog box to be displayed at the end of my game so that the player can enter its name to save it. The problem is when I call <code>show()</code> on the dialog appears but it's not vertically centered! It's a bit lower than it should and no matter what properties I set in the xml or when using <code>setGravity()</code>.</p>
  
  <p>I think this is the same problem as <a href="https://groups.google.com/forum/#!topic/android-developers/HvIcTvxj-Ws" rel="nofollow noreferrer">the one mentioned here</a>, but no one gave a proper answer.</p>
  
  <p>Thanks for your help.</p>
  
  <p>For more details, here is my code:</p>
  
  <pre><code>    AlertDialog.Builder builder;
  
      LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
      View layout = inflater.inflate(R.layout.newrecord,(ViewGroup)findViewById(R.layout.shoot));
  
      builder = new AlertDialog.Builder(this);
      builder.setView(layout);
  
      newRecDialog = builder.create();
  </code></pre>
  
  <p>And here is the code of the first element of the XML layout of <code>newrecord.xml</code>:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:gravity="center"
   android:padding="10dp"
  android:baselineAligned="true"&gt;
  </code></pre>
  
  <p>Here is the output screenshot:
  <a href="https://i.stack.imgur.com/goEEO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/goEEO.png" alt="alt text"></a><br>
  <sub>(source: <a href="http://the.niox.free.fr/divers/dialog_offset.png" rel="nofollow noreferrer">free.fr</a>)</sub>  </p>