3

在此处输入图像描述 我正在尝试使用 RecyclerView 和 GridLayoutManager 实现类似于上图的布局,我尝试根据位置设置 setSpanSizeLookup,但无法模仿上面的设计。

有人可以帮忙吗?

更新

在此处输入图像描述

4

1 回答 1

11
 private GridLayoutManager getGridLayoutManager() {
    final GridLayoutManager manager = new GridLayoutManager(getActivity(), 6);
    manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            int index = postion % 5;
            switch(index){
               case 0: return 2;
               case 1: return 2;
               case 2: return 2;
               case 3: return 3;
               case 4: return 3;
            }
           }
    });
    return manager;
}

保证金更新

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
  private int space;

  public SpacesItemDecoration(int space) {
       this.space = space;
   }

   @Override
  public void getItemOffsets(Rect outRect, View view, 
  RecyclerView parent, RecyclerView.State state) {
    outRect.right = space;
    outRect.bottom = space;
  }
 }
于 2015-07-20T08:43:51.680 回答