【问题标题】:How to set a fixed number of rows in android gridView?如何在android gridView中设置固定的行数?
【发布时间】:2012-12-19 13:49:11
【问题描述】:

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

【问题讨论】:

    标签: java android gridview


    【解决方案1】:

    我用过这样的东西,它不是 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"
    >
    

    您将有 10 行和 10 列。

    【讨论】:

      【解决方案2】:

      我不建议这样做,但如果您使用大于 14 的 API 14,您可以使用此代码 设置列数和行数

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

      来自 Java

      setRowCount(int rownumber );
      

      享受

      【讨论】:

        【解决方案3】:

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

        【讨论】:

        • 我们需要固定数量的行和列用于钻石冲刺游戏等应用程序。不会有任何第二行。
        【解决方案4】:

        GridView 并不是真正为此目的而设计的,它旨在以有效的滚动方式显示无限量的数据。如果您想创建一个静态布局,您可以将项目离散地放置在特定位置,您应该查看GridLayoutTableLayout

        【讨论】:

        • 这个答案是正确的,但如果你仍然想使用 gridview,那么你可以设置 android:numColumns="10" 然后在你的适配器中你可以喂它 100 个项目,这应该导致 10x10网格视图,享受。
        【解决方案5】:

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

        【讨论】:

        • 如果我们需要固定的行数和列数的应用程序,如钻石冲刺游戏,我们如何设置固定的行数?
        • 我猜 Devunwired 有答案。
        • 我创建了一个 GridView 并使用适配器在其中插入了 9 个项目。但它只显示一行(3 个项目)。我错过了什么吗?
        猜你喜欢
        • 2013-08-04
        • 1970-01-01
        • 2017-07-27
        • 1970-01-01
        • 2016-07-13
        • 2023-01-18
        • 2015-06-10
        • 2011-10-10
        • 1970-01-01
        相关资源
        最近更新 更多