我想要一个全屏幕网格与RecyclerView
与GridLayoutManager
但由于某种原因在行之间以及在我的RecyclerView
的顶部和底部添加了一个水平空间。我无法摆脱它。我搜索了解决方案,并试图通过将尺寸设置为0来明确地尝试ItemDecorator
,但这不起作用。没有别的工作。如何使用GridLayoutManager删除RecyclerView中的行之间的间距
The image。
我的ItemDecorator
的代码非常标准,包括在内。
private class RecyclerViewItemDecorator extends RecyclerView.ItemDecoration {
private int spaceInPixels;
public RecyclerViewItemDecorator(int spaceInPixels) {
this.spaceInPixels = spaceInPixels;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.left = spaceInPixels;
outRect.right = spaceInPixels;
outRect.bottom = spaceInPixels;
if (parent.getChildLayoutPosition(view) == 0) {
outRect.top = spaceInPixels;
} else {
outRect.top = 0;
}
}
}
这些是我使用的布局文件。
/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.korah.moviesapp.MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_fragment"
android:name="com.example.korah.moviesapp.MainActivityFragment"
tools:layout="@layout/activity_main_fragment"
>
</fragment>
</RelativeLayout>
/layout/activity_main_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/movies_recycler"
xmlns:android="http://schemas.android.com/apk/res/android">
</android.support.v7.widget.RecyclerView>
/layout/activity_movies_grid.xml
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/imageView"
android:src="@drawable/interst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" />
尝试为ImageView设置scaleType =“fitXY”?? – sJy
是兄弟!你是一个救星,让这个答案,我会接受它。 – Courtney