title: Android - Custom Dialog is too large
body: <p>I'm having some serious problems defining my own alert-style dialog, with sexy colours and logos and stuff. It all works nicely and I'm nearly there, just one little problem. </p>
  
  <p>The dialog fills the entire screen when there is a lot of text. Looking at normal alert dialogs, when the message is very long, there is a nice maximum width and height that the scroll view occupies.</p>
  
  <p>Can anyone tell me either how to emulate the dimensions of a conventional alert dialog using this set-up? </p>
  
  <p>From the various threads I have looked at this is the solution I have (apologies for the length of the code, I guess the most significant piece is the scrollview in the xml):</p>
  
  <p>MyDialog.java</p>
  
  <pre><code>public class MyDialog extends Dialog {
  
      public MyDialog(Context context, int theme) {
          super(context, theme);
          // TODO Auto-generated constructor stub
      }
  
  }
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>MyDialog dialog = new MyDialog(getActivity(), R.style.greenDialog);
  dialog.setContentView(R.layout.dialog_about);
  TextView titleTextView = (TextView) dialog.findViewById(R.id.alertTitle);
  titleTextView.setText(title);
  
  TextView text = (TextView) dialog.findViewById(R.id.message);
  text.setText("Blah blah blah" +
          "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris mollis tristique egestas. Aliquam rutrum auctor mi, ac convallis quam accumsan a. In hac habitasse platea dictumst. Mauris molestie mauris libero, sit amet tincidunt risus scelerisque eget. Morbi eu semper odio. Phasellus sollicitudin elementum lorem. Phasellus vel mauris augue. Quisque hendrerit adipiscing elementum. Integer leo mi, placerat et sodales sit amet, pretium id diam. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec id vehicula lacus.\n" +
          "\n" +
          "Phasellus enim leo, aliquam eu ante eu, accumsan lacinia enim. Etiam vitae sapien ullamcorper felis faucibus accumsan eu eget nibh. Integer tristique, metus sit amet ornare pretium, justo nunc consequat mi, ac ultricies lectus massa quis mauris. Vivamus lectus elit, condimentum vitae tincidunt at, feugiat sed quam. Mauris sollicitudin lacus ut diam rhoncus blandit. Phasellus ac lacus risus. Praesent convallis, libero non suscipit porttitor, lectus lacus congue tellus, vitae pulvinar quam dui sit amet enim.\n" +
          "\n" +
          "Quisque vehicula, elit ut mattis tempor, urna nisi ullamcorper odio, vitae commodo velit ante tincidunt urna. Duis condimentum sed nibh in faucibus. Suspendisse est felis, vestibulum sed volutpat volutpat, mattis eu sem. Morbi fermentum lorem a neque tristique, auctor interdum risus tempus. Morbi tempor nibh lorem, id accumsan lectus imperdiet sed. Nulla et sollicitudin eros, mattis dignissim lacus. Nam pulvinar magna non justo lobortis viverra. Etiam quis venenatis justo. Quisque non libero vitae magna ullamcorper laoreet. Praesent dignissim erat sit amet mi mattis sagittis. Morbi quis neque feugiat nulla fringilla sagittis. Mauris dui arcu, feugiat in dolor sed, accumsan placerat ligula.\n" +
          "\n" +
          "Suspendisse tempor enim et augue scelerisque, non rhoncus massa ultricies. Phasellus malesuada tempus ultrices. Proin dapibus sagittis orci sed ullamcorper. Phasellus lacus sem, auctor ut tincidunt at, suscipit ultricies ipsum. Nunc eget lectus elit. Aenean posuere volutpat purus, et accumsan nibh malesuada a. Vivamus egestas sed felis sed viverra. Pellentesque id elit ut leo rhoncus fermentum. Nullam id purus odio. Sed eu sapien vitae ante scelerisque tempus sed sit amet nisl. Vivamus nec orci suscipit, interdum libero quis, fringilla massa.\n" +
          "\n" +
          "Nunc laoreet condimentum fringilla. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam facilisis vulputate sapien, ac eleifend augue. Sed eget justo gravida, volutpat risus quis, sodales est. Integer blandit a ligula in molestie. Sed et turpis gravida, placerat eros ac, porta nisi. Quisque in elit a dui malesuada lobortis. Quisque pretium justo vel justo mollis, eget cursus metus condimentum. Praesent ultrices ante libero, sit amet molestie orci dictum sed. Suspendisse elementum a felis at malesuada. Sed tempus nulla sit amet enim pulvinar, vel elementum ante imperdiet. Proin vitae ligula pellentesque, aliquam lectus ac, luctus ipsum.");
  
  Button btn = (Button)dialog.findViewById(R.id.button1);
  btn.setText("OK");
  
  dialog.show();
  </code></pre>
  
  <p>dialog_about.xml</p>
  
  <pre><code>&lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/parentPanel"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingTop="9dip"
      android:paddingBottom="3dip"
      android:paddingStart="3dip"
      android:paddingEnd="1dip"&gt;
  
      &lt;LinearLayout android:id="@+id/topPanel"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:minHeight="54dip"
          android:orientation="vertical"&gt;
          &lt;LinearLayout android:id="@+id/title_template"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:layout_marginTop="6dip"
              android:layout_marginBottom="9dip"
              android:layout_marginStart="10dip"
              android:layout_marginEnd="10dip"&gt;
              &lt;ImageView android:id="@+id/icon"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="top"
                  android:paddingTop="6dip"
                  android:paddingEnd="10dip"
                  android:src="@drawable/ic_launcher" /&gt;
              &lt;TextView
                  android:id="@+id/alertTitle"
                  style="?android:attr/textAppearanceLarge"
                  android:layout_gravity="center_vertical"
                  android:singleLine="true"
                  android:ellipsize="end"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" /&gt;
          &lt;/LinearLayout&gt;
          &lt;ImageView android:id="@+id/titleDivider"
              android:layout_width="match_parent"
              android:layout_height="9dp"
              android:src="@drawable/horizontal_divider" /&gt;
          &lt;!-- If the client uses a customTitle, it will be added here. --&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout android:id="@+id/contentPanel"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:orientation="vertical"&gt;
          &lt;ScrollView android:id="@+id/scrollView"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:paddingTop="2dip"
              android:paddingBottom="12dip"
              android:paddingStart="14dip"
              android:paddingEnd="10dip"
              android:overScrollMode="ifContentScrolls"&gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical"
                  android:padding="5dip"&gt;
  
                  &lt;TextView android:id="@+id/message"
                      style="?android:attr/textAppearanceMedium"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"/&gt;
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:orientation="horizontal"&gt;
                      &lt;ImageView
                          android:layout_width="0dp"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:src="@drawable/img_view_logo_small_splash"
                          android:scaleType="centerInside"
                          android:layout_gravity="end"/&gt;
  
                      &lt;TextView android:id="@+id/legal"
                          style="?android:attr/textAppearanceSmall"
                          android:text="\u00a9 My Company Ltd. info"
                          android:layout_weight="1"
                          android:layout_width="0dp"
                          android:layout_height="wrap_content"/&gt;
                  &lt;/LinearLayout&gt;
              &lt;/LinearLayout&gt;
          &lt;/ScrollView&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout android:id="@+id/buttonPanel"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:minHeight="54dp"
          android:orientation="vertical" &gt;
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="horizontal"&gt;
              &lt;Button android:id="@+id/button1"
                  android:layout_width="0dip"
                  android:layout_gravity="start"
                  android:layout_weight="1"
                  android:textColor="@color/green_lightest"
                  android:background="@drawable/selector_transparent_button"
                  android:maxLines="2"
                  android:layout_height="match_parent" /&gt;
              &lt;Button android:id="@+id/button2"
                  android:layout_width="0dip"
                  android:layout_gravity="end"
                  android:layout_weight="1"
                  android:background="@drawable/selector_transparent_button"
                  android:maxLines="2"
                  android:layout_height="wrap_content"
                  android:visibility="gone"/&gt;
          &lt;/LinearLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This follows very closely to android's alert_dialog.xml Another thing to note is the style uses the no title feature, otherwise I was getting strange empty padding:</p>
  
  <p>styles.xml</p>
  
  <pre><code>&lt;style name="greenDialog" parent="android:Theme.Dialog"&gt;
      &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt;
      &lt;item name="android:windowBackground"&gt;@color/green_shadow&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>Screen shot of alert dialog:</p>
  
  <p><img src="https://i.stack.imgur.com/J2iXd.png" alt="Alert Dialog Problem"></p>
  
  <p>Edit: For comparison here is a normal alert dialog with the same text:</p>
  
  <p><img src="https://i.stack.imgur.com/iJyL8.png" alt="Alert Dialog Normal"></p>