效果如图
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);设置装饰器
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(mHeadAdapter);装饰器第一个item不偏移,代码为
recyclerView.addItemDecoration(new HDHeadItemDecoration(ScreenUtils.getPixel(this,-15)));
public class HDHeadItemDecoration extends RecyclerView.ItemDecoration{Adapter里面的代码就不贴了。核心思想就是装饰器的间距为负数,实现重叠效果
private int space;
public HDHeadItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (parent.getChildLayoutPosition(view)!=0){
outRect.left = space;
}
}
}