GridLayoutManager跨度大小RecycleView [英] GridLayoutManager Span Size RecycleView

查看:180
本文介绍了GridLayoutManager跨度大小RecycleView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用RecyclerView和GridLayoutManager来实现类似于上图的布局,我尝试根据位置设置setSpanSizeLookup,但无法模仿上面的设计.

I'm trying to achieve a layout similar to the picture above with the RecyclerView in conjunction with the GridLayoutManager, i tried setting the setSpanSizeLookup based on position but couldn't mimic the design above..

有人可以帮忙吗?

更新

推荐答案

 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;
  }
 }

这篇关于GridLayoutManager跨度大小RecycleView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆