Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android gridView项目宽度问题_Android_Gridview - Fatal编程技术网

Android gridView项目宽度问题

Android gridView项目宽度问题,android,gridview,Android,Gridview,我创建了GridView,并将CheckedTextView作为项 这里是我的XML格式的Gridview <GridView android:id="@+id/grid_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numColumns="auto_fit" android:horizontalS

我创建了GridView,并将CheckedTextView作为项

这里是我的XML格式的Gridview

<GridView
    android:id="@+id/grid_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"                
    android:numColumns="auto_fit"
    android:horizontalSpacing="5dip"
    android:verticalSpacing="5dip"                
    android:gravity="center"                       
    android:choiceMode="multipleChoice"/>

这里是XML格式的GridView项

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/checkedTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:textColor="@color/gray_color"    
    android:background="@drawable/shape_rectangle"/>

但它在一行中显示两个项目,每个项目显示额外的空间,如下所示


如何避免GridView中每个项目的多余空间?

尝试在项目的宽度和高度中使用match\u parent,不确定是什么问题,但我也遇到了这个问题,告诉我这是否解决了问题,否则,我将查看我的旧项目,并为您提供另一个解决方案

即使在项目的宽度和高度中使用match_parent,也会遇到同样的问题请将此android:stretchMode=“none”检查到您的gridView声明中如果使用android:stretchMode=“none”,则gridView不出现使用android:columnWidth=“40dip”的Gits但是如何避免在这里硬编码的值。将它放入您的值/dimens.xmlI也有同样的问题吗?如何减少每个网格项占用的水平空间?