2016-07-25 51 views

回答

2

可以實現這種RecyclerView行爲與twoway-view

我測試了這個LIB的1.0.0-快照版本。

這是一種舊的項目(不再維護),但它可以幫助你編寫你自己的RecyclerView/LayoutManager。佈局的

在RecyclerViewAdapter需要設置跨度邏輯:

@Override 
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 
     super.onBindViewHolder(holder, position); 
     final SpannableGridLayoutManager.LayoutParams lp = 
       (SpannableGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams(); 

     final int span1; 
     final int span2; 
     if (position == 0) { 
      span1 = 2; 
      span2 = 2; 
     } else if (position == 3) { 
      span1 = 2; 
      span2 = 3; 
     } else { 
      span1 = 1; 
      span2 = 1; 
     } 

     final int colSpan = (span2); 
     final int rowSpan = (span1); 

     if (lp.rowSpan != rowSpan || lp.colSpan != colSpan) { 
      lp.rowSpan = rowSpan; 
      lp.colSpan = colSpan; 
      holder.itemView.setLayoutParams(lp); 
     } 
} 

我使用的自定義RecyclerView從庫(TwoWayView):

<org.lucasr.twowayview.widget.TwoWayView 
     android:id="@+id/fragment_drawer_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="60dp" 
     android:clipToPadding="false" 
     android:paddingBottom="32dp" 
     app:twowayview_layoutManager="SpannableGridLayoutManager" 
     app:twowayview_numColumns="3" 
     app:twowayview_numRows="3" /> 

結果截圖: result screenshot