Skip to content Skip to sidebar Skip to footer

Dialogfragment Set Height Of Dialog

I just used created by first Dialog using DialogFragment. Everything works great except I can't get the Dialog to wrap it's layout. My layout has the height of all elements to wrap

Solution 1:

It turns out to be an issue with LinearLayout despite setting a height on it, in DialogFragment it seems to be taking more space than I want it to. I switched layout to be a RelativeLayout the content Dialog seems to resize to fit the content.

Solution 2:

You can make it work with all kind of layout in adding the size of the layout in the onResume of your dialogFragment :

@OverridepublicvoidonResume()
    {
        super.onResume();
        Windowwindow = getDialog().getWindow();
        window.setLayout(300, 300);
        window.setGravity(Gravity.CENTER);
}

Solution 3:

I took a leap into the Dialog api so I am certainly not sure but you could try to call getWindow on the dialog and then call setLayout(width, height)

getDialog().getWindow().setLayout(300,300);

Solution 4:

I don't see the top portion of your LinearLayout tag, but I've seen cases where all that was needed was the

android:orientation="vertical"

XML attribute. It can cause a headache but is fortunately easy to fix.

Post a Comment for "Dialogfragment Set Height Of Dialog"