【问题标题】:GridLayoutManager Span Size RecycleViewGridLayoutManager 跨度大小 RecycleView
【发布时间】:2015-07-20 08:16:57
【问题描述】:

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

有人可以帮忙吗?

更新

【问题讨论】:

    标签: android view android-recyclerview gridlayoutmanager


    【解决方案1】:
     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;
      }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      相关资源
      最近更新 更多