【问题标题】:How to remove horizontal space between Gridview?如何删除Gridview之间的水平空间?
【发布时间】:2019-01-23 17:15:41
【问题描述】:

我在使用 Gridview 时遇到了一个问题,Gridview 会自动在 2 个水平项目之间占据空白,即使我的适配器项目高度和宽度是 match_parent。

我已经尝试了旧问题的所有答案,但我也遇到了同样的错误。

我尝试的链接是: * GridView : Removing spaces between horizontal and vertical spaces

*How to remove Horizontal spacing between the grid view in android?

主xml代码:

<GridView
    android:id="@+id/gvCurrentMonthDayList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:verticalSpacing="2dp"
    android:background="#EEEEEE"
    android:horizontalSpacing="2dp"
    android:stretchMode="columnWidth"
    android:numColumns="7"
    />

子项代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llCalendarItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/txtCount"
    android:text="123"
    android:textColor="@android:color/black"
    android:textSize="@dimen/h5" />
<TextView
   android:layout_width="@dimen/common_10_dp"
   android:gravity="center"
   android:id="@+id/txtCount"
   android:background="@drawable/event_count_back"
   android:text="10"
   android:layout_alignParentRight="true"
   android:layout_centerVertical="true"
   android:textColor="#fff"
   android:textSize="@dimen/common_5_dp"
   android:layout_height="@dimen/common_10_dp" />
</RelativeLayout>

错误截图:

【问题讨论】:

    标签: android android-gridview android-gridlayout


    【解决方案1】:

    我认为您的 xml 文件中有 android:horizo​​ntalSpacing。

    将其设为零,然后检查输出。

    【讨论】:

    • 将 android:id="@+id/date" 宽度更改为 match_parent 而不是尝试。这可能会改变输出
    • 那么结果也一样
    • 把你的密码发给我[没有你的密码] dharmikjagodana007@gmail.com
    • 将子元素的根元素设置为frameLayout,并使子元素的宽度与父元素匹配[android:id="@+id/date"]
    【解决方案2】:

    尝试将值android:horizontalSpacing="2dp"更改为android:horizontalSpacing="1dp"0dp

    【讨论】:

    • 那么结果也一样
    • 你的 child.xml* 中第二个TextView 的作用是什么?