2016-02-03 99 views
0

我有一個片段,其中包含兩個RecyclerViews(一個在兩列的網格,另一個爲我的實際飼料)。自定義GridLayoutManager提供與WRAP_CONTENT RecyclerView

<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" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 


<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:scrollbars="none" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/second_recycler_view" 
    android:scrollbars="none" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/recycler_view" 
    /> 

如何實現兩個RecyclerViews在一個佈局?

回答

0

嘗試使用單一RecyclerView與定製SpanSizeLookup一個GridLayoutManager:

GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2); 
    GridLayoutManager.SpanSizeLookup columnSpanner = new GridLayoutManager.SpanSizeLookup() { 
     @Override 
     public int getSpanSize(int position) { 
      return adapter.getItemViewType(position) == R.layout.your_two_column_row_layout ? 1 : 2; 
     } 
    }; 
    gridLayoutManager.setSpanSizeLookup(columnSpanner); 
    recyclerView.setLayoutManager(gridLayoutManager); 

,並使用不同的持有人對您的適配器不同類型的列。

相關問題