Search code examples
androidlayoutfill-parent

android: layout: How to make my dialog box fill the screen with the XML


I'm trying to get a Dialog box to open covering most the screen (by that I mean it still has its nice rounded effect but cover the content behind)

I've been trying with fill parent but it keeps behaving like a wrap content

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
 >


<LinearLayout
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <SurfaceView android:id="@+id/surface"
        android:layout_width="400px"
        android:layout_height="200px"
        android:layout_centerHorizontal="true">
    </SurfaceView>
    <Button android:id="@+id/Button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="Ok, Let me play !!!" />
</LinearLayout>
</LinearLayout>

I tried the solution here

How can I get a Dialog style activity window to fill the screen?

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

and it does what I want

so now I want to know what is worng in my xml (I try to put all layout behavior inside the xml rather than in my code if I can help it ^^)


Solution

  • As I understand it the issue that the solution to How can I get a Dialog style activity window to fill the screen? solved was that the layout had to be modified after the xml had been loaded. Basically there is no xml that can do this alone.