additemdecoration重复_两个RecyclerView.ItemDecoration彼此重叠

In our app we use two ItemDecorations in RecyclerView. One is StickyHeader to show dates, and other is header to show New Messages header. Problem is that when they are added to same item, they overlap each other. How I can prevent this from happening.

StickyRecyclerHeadersDecoration headersDecoration = new StickyRecyclerHeadersDecoration(getAdapter());

recyclerView.addItemDecoration(headersDecoration);

NewMessageHeaderDecoration newMessageHeader = new NewMessageHeaderDecoration();

recyclerView.addItemDecoration(newMessageHeader);

解决方案

I used this code from here to solve two ItemDecoration overlap. (For more details check comment by @bejibx)

public void drawVertical(Canvas c, RecyclerView parent)

{

RecyclerView.LayoutManager manager = parent.getLayoutManager();

final int left = parent.getPaddingLeft();

final int right = parent.getWidth() - parent.getPaddingRight();

final int childCount = parent.getChildCount();

for (int i = 0; i < childCount; i++)

{

final View child = parent.getChildAt(i);

final int top = manager.getDecoratedBottom(child);

final int bottom = top + mDivider.getIntrinsicHeight();

mDivider.setBounds(left, top, right, bottom);

mDivider.draw(c);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值