GridView不支持columnCount

问题描述

下面有一些代码用于在GridView中呈现列表:

LevelActivity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <GridView
        android:id="@+id/levelGridView"
        android:columnCount="3"
        android:alignmentMode="alignMargins"
        android:columnorderPreserved="false"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

LevelItem.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/levelItem"
    android:layout_gravity="center"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:onClick="startGame"
        android:tag="1"
        app:cardElevation="6dp"
        app:cardCornerRadius="12dp"
        android:layout_margin="12dp">
        
        <LinearLayout
            android:orientation="vertical"
            android:padding="16dp"
            android:layout_gravity="center"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            
            <TextView
                android:id="@+id/level_id"
                android:gravity="center"
                android:textColor="#6F6F6F"
                android:textSize="18sp"
                android:text="Level 1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
                
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>

哪个呈现如下:

enter image description here

我很困惑,因为我希望有3个具有android:columnCount="3"属性的列,但是只有一列。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...