shuhart / stickyheader Goto Github PK
View Code? Open in Web Editor NEWA simple lightweight sticky header ItemDecorator for RecyclerView
License: Apache License 2.0
A simple lightweight sticky header ItemDecorator for RecyclerView
License: Apache License 2.0
Hi,
The item underneath my header item gets clicked. If i scroll the list and if there is an item under the header item then whatever the function underneath item has get clicked. How do i resolve it ?
Hello,
I was playing around with the sample app you've provided and I noticed a quirk with the top header, along with a crash.
The first issue might be related to #4, but I did not see a full on extra header. Gif shown below.
https://i.imgur.com/BW2NiG9.gif
The second issue is the crash. Playing with the sample app, if you go a little crazy scrolling up and down, the following crash happens.
2019-05-22 19:59:58.346 27441-27441/com.shuhart.stickyheader.sample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.shuhart.stickyheader.sample, PID: 27441 java.lang.ArrayIndexOutOfBoundsException: length=33; index=-1 at java.util.ArrayList.get(ArrayList.java:439) at com.shuhart.stickyheader.sample.SectionAdapter.getHeaderPositionForItem(SectionAdapter.java:53) at com.shuhart.stickyheader.StickyHeaderItemDecorator.onDrawOver(StickyHeaderItemDecorator.java:81) at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:4017) at android.view.View.updateDisplayListIfDirty(View.java:19082) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4317) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4290) at android.view.View.updateDisplayListIfDirty(View.java:19042) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4317) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4290) at android.view.View.updateDisplayListIfDirty(View.java:19042) <Repeats many more times>
StickyHeaderItemDecorator not calls onBindHeaderViewHolder
onBindHeaderViewHolder method is not called by StickyHeaderItemDecorator.
The library works fine, but how can I make it so that only the headers can change the pinned header? Any help
I want to hide header if there is only one section in list but i am not able to fine any way to do this, if I hide main view of header then some space still there.
Hello!
I've tried this library and the sample codes worked as I expected. That's great!
However, I noticed that if the items held by RecyclerView has margin (represented as android:marginTop/Bottom
) or divider (that is provided by using DividerItemDecoration
), sticky header causes glitches if the margin/divider part contacts to the header.
I dived into the implementation, I guess following part should be corrected not to return but continue to latter part.
// Here're methods in StickyHeaderItemDecorator.java
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
// omit former part
View viewOverlappedByHeader = getChildInContact(parent, currentStickyHolder.itemView.getBottom());
if (viewOverlappedByHeader == null) {
// ****** if return here, sticky header disappeared. ******
return;
}
// omit latter part
}
// "margin" or "divider" contacts to the sticky header, this method probably return null.
private View getChildInContact(RecyclerView parent, int contactPoint) {
View childInContact = null;
for (int i = 0; i < parent.getChildCount(); i++) {
View child = parent.getChildAt(i);
if (child.getBottom() > contactPoint) {
if (child.getTop() <= contactPoint) {
// This child overlaps the contactPoint
childInContact = child;
break;
}
}
}
return childInContact;
}
I think this is not expected behavior of this library. How do you think?
If getChildInContact
returns null
, I guess onDrawOver
should not return then but should continue to proceed with a view that is "last contacted".
Just my idea, onDrawOver
method should be like this:
// prepare a view represents "last contacted"
private View lastViewOverlappedByHeader = null;
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
// omit former part
View viewOverlappedByHeader = getChildInContact(parent, currentStickyHolder.itemView.getBottom());
if (viewOverlappedByHeader == null) {
// continue processing with "last contacted"
if (lastViewOverlappedByHeader != null) {
viewOverlappedByHeader = lastViewOverlappedByHeader;
} else {
return;
}
}
// omit latter part
}
If you can agree, I'll try to create a pull request for this issue. Please let me know.
Thanks!
I have a RecyclerView that uses the library, adding a paddingTop
and clipToPadding = false
, adds an unwanted header to the top
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/countriesList"
android:layout_width="0dp"
android:layout_height="0dp"
android:paddingTop="30dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/country_list_item">
</androidx.recyclerview.widget.RecyclerView>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.