2016-07-26 3 views
4

Ich versuche, ein Vollbildraster mit einem mit einem GridLayoutManager zu haben, aber aus irgendeinem Grund wird ein horizontaler Abstand zwischen den Zeilen und oben und unten von meinem RecyclerView hinzugefügt. Ich kann es nicht loswerden. Ich suchte nach Lösungen und versuchte eine ItemDecorator, indem ich die Dimensionen explizit auf 0 setzte, aber das hat nicht funktioniert. Nichts anderes hat funktioniert.So entfernen Sie den Abstand zwischen Zeilen in RecyclerView mit GridLayoutManager

Die image.

Der Code für meine ItemDecorator ist ziemlich Standard, enthalten.

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; 
     } 
    } 
} 

Dies sind die Layoutdateien, die ich verwende.

/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

Versuchen Sie die Einstellung scaleType = "fitXY" für ImageView ?? – sJy

+0

Ja, Bruder !!!! Du bist ein Lebensretter, mach das zur Antwort und ich werde es akzeptieren. – Courtney

Antwort

4

Sollte wegen der Skalierung von Image eher als alles andere sein. Versuchen Sie also, scaleType von ImageView als fitXY zu setzen.

<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

Bild sieht jetzt besser aus. aber das Problem nicht gelöst –

Verwandte Themen