Android Grid view with 3 rows and 3 columns
Asked Answered
K

1

6

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

Klaipeda answered 17/7, 2014 at 6:16 Comment(6)
Please show your code.Giusto
If you have fixed number of rows and columns then why don't you go with TableLayout!Platinous
for columns you can use android:numColumns but for rows you must do that in your codeElectromechanical
<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>Klaipeda
it can't be because number of item may increase you can only set one parameter at a time . i think .Billie
if you need to show only 3 rows,Specify that in gridview adapter getCount(). and print values inside getView() manually.Lever
L
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.

Looselimbed answered 17/7, 2014 at 6:21 Comment(6)
zeus, thanks for you quick response. But how to add 3 rows. thats what my question :(Klaipeda
@Deepak if you want fixed rows you need get height of gridView then set height of each row to viewhigh/ 3,Electromechanical
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.Looselimbed
@mzeus.bolt I have a issue in Gridview can you please help me to solve .Hatley
What issue are you facing @HatleyLooselimbed
Please look it #49963679 @mzeus.boltHatley

© 2022 - 2024 — McMap. All rights reserved.