Andrew Martin
Andrew Martin

Reputation: 5741

Using LayoutInflator to create a dialog that takes up whole screen

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" />

Upvotes: 0

Views: 1075

Answers (1)

waqaslam
waqaslam

Reputation: 68187

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

dialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

Upvotes: 1

Related Questions