我在使用Gridview时遇到问题,即使我的适配器项目的高度和宽度都是match_parent,Gridview也会自动在2个水平项目之间占用空白。
我已经尝试过旧问题类似问题的所有答案,但我也遇到相同的错误。
我尝试的链接是: * 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>
错误的屏幕截图:
答案 0 :(得分:0)
我认为您的xml文件中有android:horizontalSpacing。
将其设为零,然后检查输出。
答案 1 :(得分:0)
尝试将值android:horizontalSpacing="2dp"
更改为android:horizontalSpacing="1dp"
或0dp