主要通调用调用recyclerView 的 setITemDecoration 方法
AppinfoiItemDecoration decor = new AppinfoiItemDecoration(); //设置条目的间距 recycler.addItemDecoration(decor);
AppinfoiItemDecoration 继承RecyclerView.ItemDecoration 方法
复写 getItemOffsets 方法设置left right bottom 和top 的距离
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { //不是第一个的格子都设一个左边和底部的间距 int pos = parent.getChildAdapterPosition(view); outRect.left = 10; if (pos != 0) { if (pos % 2 == 0) { //下面一行 outRect.bottom =30; outRect.top = 5; } else { //上面一行 outRect.top = 30; outRect.bottom = 5; } } }