2016-07-15 53 views
0

我想该行设置不同的列布局,我在下面的图片显示如何设置行不同列中的Android RecycleView

enter image description here

我想这种类型的布局目前我得到的两个图像对每一行使用recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));那么,如何才能做到这一点。

RecycleView项目布局像

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<com.gordonwong.materialsheetfab.sample.SquareImageView 
    android:id="@+id/phone" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="centerCrop" /> 

,并在像

recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); 
    adapter = new GridViewAdapter(getActivity(), infoarraylist); 
    recyclerView.setAdapter(adapter); 
    recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); 
    Collections.reverse(infoarraylist); 
    recyclerView.setItemAnimator(new DefaultItemAnimator()); 

回答

-1
mLayoutManager = new GridLayoutManager(getActivity(), 2); 
     mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 
      @Override 
      public int getSpanSize(int position) { 
       if (infoarraylist.get(position) instanceof YOUROBJECT) { 
        return 1; 
       } else if (infoarraylist.get(position) instanceof YOUROBJECT) { 
        return 2; 
       } 
       return -1; 
      } 
     }); 
     recyclerView.setLayoutManager(mLayoutManager); 
     recyclerView.setAdapter(adapter); 
+0

是什么YOUROBJECT在你的代码的含义。我的类文件集适配器?有没有什么ArrayList的话,我喜欢使用ArrayList中... infoarraylist这种类型的列表,怎么怎么我可以在你的代码 –

+0

配置你需要创建数组列表并将其设置为适配器 – Pavya

+0

ok了,然后看到我像适配器... adapter = new GridViewAdapter(getActivity(),infoarraylist); –

相关问题