0

Ich versuche, eine RecyclerView mit einer GridLayoutManager in meiner Android-Anwendung zu implementieren. Die CardView Elemente innerhalb der RecyclerView werden vertikal angezeigt, als ob sie in einem LinearLayout waren. Wie kann ich sie zwingen, das Raster von links nach rechts, Zeile für Zeile, zu füllen?Android RecyclerView und GridLayoutManager Layout

Hier ist mein RecyclerView Layout-Code:

<android.support.v7.widget.RecyclerView 
    android:id="@+id/RECYCLER_VIEW" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="@dimen/item_offset" /> 

Hier mein CardView Layout-Code ist:

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/card_view" 
card_view:cardUseCompatPadding="true" 
android:layout_width="120dp" 
android:layout_height="120dp"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="10dp" 
     android:layout_alignParentBottom="true" 
     android:textAlignment="center" 
     android:textSize="18dp" /> 

</RelativeLayout> 
</android.support.v7.widget.CardView> 

Hier ist der Code onCreate Methode ist die RecyclerView in der Aktivität (CustomAdapter erstreckt RecyclerView.Adapter einzurichten):

 // set up adapter 
     adapter = new CustomAdapter(getApplicationContext(), ApplicationState.getGridElements()); 
     view.setAdapter(adapter); 

     // grid layout manager with 2 columns 
     GridLayoutManager layoutManager = new GridLayoutManager(this, 2); 
     view.setLayoutManager(layoutManager); 

     // custom decoration for equal spacing 
     ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(getApplicationContext(), R.dimen.item_offset); 
     view.addItemDecoration(itemDecoration); 

     view.setHasFixedSize(true); 
+0

Sie Screenshot hinzufügen ?? –

Antwort

0
GridLayoutManager (Context context, 
       int spanCount, 
       int orientation, 
       boolean reverseLayout) 

Set reverseLayout als wahr

Verwandte Themen