重叠头像最简单实现(RecyclerView实现)

重叠头像最简单实现(RecyclerView实现)

重叠头像最简单实现(RecyclerView实现)_第1张图片
实现如图所示的头像重叠,百度一下都是自定义头像,那有没有简单的实现方式呢?答案是有的,利用RecyclerView的装饰器实现,两行代码搞定。废话不多说,上代码:

首先设置方向:

 		LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        linearLayoutManager.setStackFromEnd(true);//列表再底部开始展示
        linearLayoutManager.setReverseLayout(true);//列表翻转
        recycleview.setLayoutManager(linearLayoutManager);
        recycleview.setAdapter(adapter));

然后设置装饰器:

 recycleview.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.getChildLayoutPosition(view) != userAcatars.size() - 1) {
                    outRect.left = DeviceUtil.dp2px(LearningPlanDetailsActivity.this, -7);
                }
            }
        });

ok,至此如图效果已经实现了,就是这么简单

你可能感兴趣的:(原创,重叠头像,头像)