设计图如上面显示:后面头像重叠显示,核心就是:装饰器第一个item不偏移,其他item向左偏移一定距离,代码为:
mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); if (parent.getChildPosition(view) != (0)) { outRect.left = -6; } } });
Adapter里面的代码就不贴了。核心思想就是装饰器的间距为负数,实现重叠效果