2

I'm adding a ImageView item to the empty GridView programmatically so when i set the height to wrap content the second row disappears.

Here's the gridview xml :

    <GridView
    android:id="@+id/gridView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnWidth="100dip"
    android:gravity="center"
    android:horizontalSpacing="10dip"
    android:numColumns="2"
    android:stretchMode="spacingWidthUniform"
    android:verticalSpacing="10dip" />

I tried to set the hight to wrap content programmatically after adding the items but it didn't work, and i know that i can't predifine the number of rows, and i don't want to set a fixed height.

Any help ?

walid
  • 494
  • 3
  • 16

2 Answers2

1

In case if you have your GridView inside the ScrollView;

Problem GridView doesn't expand inside the Scroll view.

Please refer the following post.

Please Follow the Stackoverflow post answer

Community
  • 1
  • 1
0

Make your ParentLayout to fill_parent and then make GridView wrap_content.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
  • Then you have to create another sub parent layout for this, take your GridView into new Sub Parent layout and make it match_parent or fill_parent. – Pratik Dasa Sep 10 '13 at 12:58