如图
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(linearLayoutManager);
设置装饰器
recyclerView.setAdapter(mHeadAdapter);
recyclerView.addItemDecoration(new HDHeadItemDecoration(ScreenUtils.getPixel(this,-15)));
装饰器第一个item不偏移,代码为
public class HDHeadItemDecoration extends RecyclerView.ItemDecoration{
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;
}
}
}
Adapter里面的代码就不贴了。核心思想就是装饰器的间距为负数,实现重叠效果