I try to implement a sticky header as Sevastyan Savanyuk said in:
How can I make sticky headers in RecyclerView? (Without external lib)
I have a nested recycler view in an outer recycler view. I just want my inner recycler view has a sticky header.
But onDrawOver
method just called once.
The result is that I draw the header in my onDrawOver
, but it's not sticky!
I only have one sticky header(item 0), here's my code(kotlin):
override fun isHeader(itemPosition: Int): Boolean = itemPosition == 0
override fun getHeaderPositionForItem(itemPosition: Int): Int = 0
here's my onDrawOver method:
@Override
public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
super.onDrawOver(c, parent, state);
View topChild = parent.getChildAt(0);
if (topChild == null) {
return;
}
int topChildPosition = parent.getChildAdapterPosition(topChild);
if (topChildPosition == RecyclerView.NO_POSITION) {
return;
}
int headerPos = mListener.getHeaderPositionForItem(topChildPosition);
View currentHeader = getHeaderViewForItem(headerPos, parent);
fixLayoutSize(parent, currentHeader);
int contactPoint = currentHeader.getBottom();
View childInContact = getChildInContact(parent, contactPoint, headerPos);
if (childInContact != null) {
int itemPosition = parent.getChildAdapterPosition(childInContact);
if (mListener.isHeader(itemPosition)) {
moveHeader(c, currentHeader, childInContact);
return;
}
}
drawHeader(c, currentHeader);
}
How can I get my header sticky, why does onDrawOver
method just called once, help!