title: How to specify correct dialog size in XML layout file for Android dialog?
body: <p>I have created an android dialog using an XML layout file like so:</p>
  
  <pre><code>  final Dialog dialog = new Dialog(this);
          dialog.setContentView(R.layout.enabledialog);
          dialog.setTitle("Define message keys and setup");
  
          Switch locationSwitch = (Switch) dialog.findViewById(R.id.locationSwitch);
          Switch blareSwitch = (Switch) dialog.findViewById(R.id.blareSwitch);
  
          final EditText locationEdit = (EditText) dialog.findViewById(R.id.locationEdit);
          final EditText blareEdit = (EditText) dialog.findViewById(R.id.blareEdit);
  
          WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
          lp.copyFrom(dialog.getWindow().getAttributes());
          lp.width = WindowManager.LayoutParams.MATCH_PARENT;
          lp.height = WindowManager.LayoutParams.MATCH_PARENT;
  
          dialog.show();
  
          dialog.getWindow().setAttributes(lp);
  </code></pre>
  
  <p>However, my XML file's contents only take up half of the screen, so when I display the dialog, I am showing extra space, which doesn't look nice:</p>
  
  <h2>HERE IS A SKETCH OF HOW THE DIALOG LOOKS (R.layout.enabledialog):</h2>
  
  <p><a href="https://i.stack.imgur.com/bPhw7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bPhw7.png" alt="enter image description here"></a></p>
  
  <p>How do I trim this extra space? In android studio, the layout editor assumes the XML file is to take up the whole screen, but really, I only want a small popup window.</p>
  
  <p>Thanks,</p>
  
  <p>Ruchir</p>
  
  <hr>
  
  <p><strong>EDIT: Here is my layout resource file:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="#1dd1e9"&gt;
  
  
      &lt;Switch
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/locationSwitch"
          android:layout_marginTop="46dp"
          android:checked="false"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:text="Blah"
          android:id="@+id/textView"
          android:textSize="30sp"
          android:layout_alignTop="@+id/locationSwitch"
          android:layout_centerHorizontal="true"
          /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:text="Blah Blah Blah"
          android:id="@+id/textView2"
          android:gravity="center"
          android:textSize="20sp"
          android:layout_below="@+id/locationSwitch"
          android:layout_centerHorizontal="true"
          /&gt;
  
      &lt;EditText
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/locationEdit"
          android:layout_below="@+id/textView2"
          android:layout_alignLeft="@+id/textView"
          android:layout_alignStart="@+id/textView"
          android:layout_alignRight="@+id/textView"
          android:layout_alignEnd="@+id/textView"
          android:singleLine = "true"
          android:imeOptions="actionDone" /&gt;
  
      &lt;Switch
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/blareSwitch"
          android:layout_marginTop="40dp"
          android:checked="false"
          android:layout_below="@+id/locationEdit"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:text="Blah"
          android:id="@+id/textView3"
          android:textSize="30sp"
          android:layout_alignBottom="@+id/blareSwitch"
          android:layout_centerHorizontal="true" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:text="Blah Blah Blah"
          android:id="@+id/textView4"
          android:textSize="20sp"
          android:layout_centerVertical="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;EditText
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/blareEdit"
          android:layout_below="@+id/textView4"
          android:layout_alignLeft="@+id/locationEdit"
          android:layout_alignStart="@+id/locationEdit"
          android:layout_alignRight="@+id/locationEdit"
          android:layout_alignEnd="@+id/locationEdit"
          android:singleLine = "true"
          android:imeOptions="actionDone" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>