Embedding a dialogfragment containing a gridview leads to unscrollable gridview showing only it's first row

324 Views Asked by At

I have a DialogFragment containing a Gridview. Showing it as dialog works as expected. Now, I try to embed the same DialogFragment in an Activity For that, I have a ViewStub in my Activity layout defined as follows:

<RelativeLayout>
<!-- Other children -->

    <ViewStub
        android:id="@+id/view_stub"
        android:layout_below="@id/tv_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:inflatedId="@+id/attachment"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

Note that I have not specified the inflated layout here. Depending on the Intent extras this Activity is started with, it can inflate one of several layouts into this stub, one of them being a placeholder for the DialogFragment:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</FrameLayout>

After checking for proper Intent extras, I inflate the above layout and add the DialogFragment with the following code:

viewStub.setLayoutResource( R.layout.dialog_fragment_placeholder );
flPlaceHolder = ( FrameLayout ) viewStub.inflate();
getSupportFragmentManager().beginTransaction()
        .add( flPlaceHolder.getId(),
                DialogFragment.newInstance( //arguments ),
                DialogFragment.TAG )
        .commit();

This leads to the DialogFragment being added, but the GridView shows only the first row and is not scrollable. In case it's needed here's the layout of the DialogFragment

<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnWidth="100dp"
    android:numColumns="auto_fit"
    android:gravity="center"
    android:background="#cc000000"
    android:listSelector="@android:color/transparent">

</GridView>

I am pretty sure the issue is because of improper layout_height/layout_width attributes in one of the layouts, but I tried messing around with all possible values in all possible files without any good results. Any help?

0

There are 0 best solutions below