5

I unable to set no. of rows for grid view. Only able to set no. of columns.

I need to create a grid view which has 3 rows and 3 columns.

Can any one help me please.

This is my XML layout code:

<GridView android:id="@+id/gridView" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:numColumns="3" 
   android:gravity="center" 
   android:stretchMode="columnWidth" > 
</GridView>

Thanks in advance, Deepak

alex
  • 5,516
  • 2
  • 36
  • 60
Dev
  • 119
  • 1
  • 4
  • 13

1 Answers1

5

Add this attribute to your android XML

android:numColumns="3"

This will allow you to have only 3 columns and give the

android:layout_width="match_parent"

Then add 3 rows may be it will help.

Try it.

Mohammed Rampurawala
  • 3,033
  • 2
  • 22
  • 32
  • zeus, thanks for you quick response. But how to add 3 rows. thats what my question :( – Dev Jul 17 '14 at 06:35
  • @Deepak if you want fixed rows you need get height of gridView then set height of each row to `viewhigh/ 3`, – Shayan Pourvatan Jul 17 '14 at 08:09
  • 1
    to setup the three rows you have to setup total 9 elements in the List or String array and use the ArrayAdapter to create the adapter to the gridView and then with the GridView object call the method setAdapter() and the setAdapter() needs the ArrayAdapter Object as the parameter. – Mohammed Rampurawala Jul 17 '14 at 08:17
  • @mzeus.bolt I have a issue in Gridview can you please help me to solve . – Nikson Apr 22 '18 at 06:07
  • What issue are you facing @Nikson – Mohammed Rampurawala Apr 22 '18 at 13:46
  • Please look it https://stackoverflow.com/questions/49963179/gridview-not-fit-for-all-screens-in-android @mzeus.bolt – Nikson Apr 22 '18 at 13:55