How to set a fixed number of rows in android gridView?

前端 未结 5 1754
余生分开走
余生分开走 2020-12-29 22:04

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 ?

相关标签:
5条回答
  • 2020-12-29 22:47

    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.

    0 讨论(0)
  • 2020-12-29 22:55

    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.

    0 讨论(0)
  • 2020-12-29 23:04

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

    0 讨论(0)
  • 2020-12-29 23:04

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

    0 讨论(0)
  • 2020-12-29 23:06

    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

    0 讨论(0)
提交回复
热议问题