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);
}
}