【发布时间】: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