如何在android gridView中设置固定行数?

时间:2021-08-22 09:12:31

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 ?

我试图在android中创建一个有10行10列的gridView。如何在Gridview中设置固定数量的行?

5 个解决方案

#1


19  

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.

GridView并非真正为此目的而设计,它旨在以高效的滚动方式显示无限量的数据。如果要创建静态布局,可以将项目分散放置在特定位置,则应该查看GridLayout或TableLayout。

#2


5  

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

我不建议这样做但是如果你使用大于14的API 14,你可以使用这个代码集的列数和行数

from xml

来自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

来自Java

setRowCount(int rownumber );

enjoy

请享用

#3


0  

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

如果您有100个项目,则只显示10行。不需要具有固定数量的行。

#4


0  

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

行数由列数和项目数自动计算(并由您强加)

#5


0  

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

我使用过这样的东西,它不是GridView,但我有类似的问题,GridLayout对我帮助很大:

<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.

你将有10行10列。

#1


19  

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.

GridView并非真正为此目的而设计,它旨在以高效的滚动方式显示无限量的数据。如果要创建静态布局,可以将项目分散放置在特定位置,则应该查看GridLayout或TableLayout。

#2


5  

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

我不建议这样做但是如果你使用大于14的API 14,你可以使用这个代码集的列数和行数

from xml

来自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

来自Java

setRowCount(int rownumber );

enjoy

请享用

#3


0  

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

如果您有100个项目,则只显示10行。不需要具有固定数量的行。

#4


0  

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

行数由列数和项目数自动计算(并由您强加)

#5


0  

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

我使用过这样的东西,它不是GridView,但我有类似的问题,GridLayout对我帮助很大:

<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.

你将有10行10列。