0

I am designing an "about" menu for an app and have used the following code in an options menu to generate it:

    case DIALOG_ABOUT:
        builder = new AlertDialog.Builder(this);
        Context context = getApplicationContext(); 
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); 
        View layout = inflater.inflate(R.layout.about_dialog, null); 
        builder.setView(layout);

        TextView title = new TextView(this);
        title.setText(R.string.about_title);
        title.setGravity(Gravity.CENTER);
        title.setTextSize(20);
        builder.setCustomTitle(title);
        builder.setPositiveButton("OK", null); 
        dialog = builder.create();
        break;

I have created two different views for the about menu - for both horizontal and vertical viewings.

When displaying vertically, the about menu looks fine, but when displaying horizontally the bottom part of the text is being cut off. I am using the LayoutInflator and View controls without having that much knowledge about how they work, so I assume they are currently filling to some Android-specified size.

How can I create the dialog to take up the whole screen, or at least 90% of it?

Edit - My layouts looked like this:

Vertical Layout:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@drawable/icon" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:text="@string/game_name"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:text="@string/game_description"
    android:textAppearance="?android:attr/textAppearanceMedium" />

Horizontal Layout:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@drawable/icon" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:text="@string/game_name"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:text="@string/game_description"
    android:textAppearance="?android:attr/textAppearanceMedium" />

Andrew Martin
  • 5,619
  • 10
  • 54
  • 92
  • Dou you have two layout in two different folders `layout` and `layout-land`? Did you use `android:height="match_parent"`? Please provide your layouts ... – Trinimon Mar 21 '13 at 21:27

1 Answers1

1

You may call the following on your dialog to fill entire space.

dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • Please note that `LayoutParams.FILL_PARENT` is deprecated; use `LayoutParams.MATCH_PARENT` instead – Trinimon Mar 21 '13 at 21:28
  • 2
    We don't know what's the api version OP using. So **LayoutParams.FILL_PARENT** is just a wild guess :) – waqaslam Mar 21 '13 at 21:31
  • I am getting messages about it being deprecated, but as my lecturer is using it everywhere, I'm just leaving it in for simplicity. Thanks for the info though on what I should be using. – Andrew Martin Mar 21 '13 at 21:31
  • @Waqas: I'm assuming I use that line after the builder.create()? I ask because I've added it in, but it's not changing the size of the screen. – Andrew Martin Mar 21 '13 at 21:33
  • you need to call this before builder.create() – waqaslam Mar 21 '13 at 22:31