25

I am trying to create one gridView in android which have 10 rows and 10 columns.How can I set a fixed number of rows in Gridview ?

KarSho
  • 5,699
  • 13
  • 45
  • 78
Ann
  • 727
  • 1
  • 7
  • 19

5 Answers5

24

GridView is not really designed for this purpose, it is designed to display an indefinite amount of data in an efficient scrolling manner. If you want to create a static layout where you can discretely place items at specific locations, you should be looking at GridLayout or TableLayout instead.

devunwired
  • 62,780
  • 12
  • 127
  • 139
  • 9
    This answer is right but if you still want to use a gridview then you can set android:numColumns="10" and then in your adapter you can feed it 100 items and this should result in a 10x10 grid view, enjoy. – DraganescuValentin Feb 12 '14 at 07:10
6

i dont recommend that but if you use API 14 greater than 14 you can use this code set number of column and rows

from xml

 <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/GridLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:columnCount="2"
    android:rowCount="2"
    android:orientation="horizontal"
    tools:context=".GridXMLActivity" >

From Java

setRowCount(int rownumber );

enjoy

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
1

I used something like this, it isn't GridView but I had the similar issue and GridLayout helped me a lot:

<GridLayout
    android:id="@+id/bottom_recycle_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="10"
    android:rowCount="10"
>

You will have 10 rows and 10 columns.

Banana
  • 2,435
  • 7
  • 34
  • 60
f.trajkovski
  • 794
  • 9
  • 24
0

If you have 100 items then only 10 rows will be shown. There is no need to have a fixed number of rows.

Oleg Vaskevich
  • 12,444
  • 6
  • 63
  • 80
0

The number of rows is automatically calculated (and imposed by you) from the number of columns and the number of items

No_Rulz
  • 2,679
  • 1
  • 20
  • 33
  • we need a fixed number of rows and columns for the application like diamond dash game.there will no any 2nd row. –  Jul 20 '14 at 05:36