2016-07-26 1 views
4

を使用してRecyclerViewの行の間の間隔を削除する方法。私はそれを取り除くことはできません。私は解決策を探して、ItemDecoratorを明示的に0に設定してみましたが、うまくいきませんでした。他に何も働かなかった。私は<code>GridLayoutManager</code>と<code>RecyclerView</code>とフルスクリーングリッドを持ってしようとしていますが、何らかの理由で水平方向のスペースが行の間、私の<code>RecyclerView</code>の最上部と最下部に追加されGridLayoutManager

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" /> 
+0

ImageViewにscaleType = "fitXY"を設定してみますか? – sJy

+0

はいbro !!!!あなたは命の恩人です、これを答えにして、私はそれを受け入れます。 – Courtney

答えて

4

他のものよりもImageのスケーリングが原因です。ですから、ImageViewのscaleTypeをfitXYと設定してみてください。

<ImageView 
    android:id="@+id/imageView" 
    android:src="@drawable/interst" 
    android:layout_width="wrap_content" 
    android:scaleType="fitXY" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android" /> 
+0

イメージが今より良く見えます。問題を解決していない –

関連する問題

 関連する問題