9

Hello All I have just created a demo to work with new android L widget RecyclerView.I have also implemented Pull-To-Refresh using SwipeRefreshLayout but problem for me now is how can I implement sticky header here,Because when i try to set

mRecyclerView.setOnScrollListener(new OnScrollListener() { @Override public void onScrolled(int arg0, int arg1) { } @Override public void onScrollStateChanged(int arg0) { // TODO Auto-generated method stub } }); 

I get only these 2 methods so dont have any idea how can I handle this...

Please help..

2
  • Please explain what type of sticky-header you are looking for? Just one header? any number of category style headers that would take the position of the last as you scroll? Commented Jul 24, 2014 at 20:52
  • 1
    Please refer the Instagram.. like Instagram I am looking for sticky header or you can say section header where each row will have that header which sticks at top till its contents get scrolled! Commented Jul 25, 2014 at 5:15

2 Answers 2

5

Since the previous answers don't provide a reliable solution, I propose my FlexibleAdapter library for RecyclerView, that is able to handle all following functionalities at once:

  • Sticky functionality for headers with Sections, works with all 3 LayoutManagers and with ViewPager too.
  • Selection Modes.
  • Multiple item types with auto-mapping.
  • Predefined ViewHolders.
  • Expandable items with Selection Coherence.
  • Draggable and Swipe-To-Dismiss.
  • Animated Async Filter with spannable text.
  • Scrolling Animations.
  • EndlessScroll with Adapter binding.
  • UndoHelper & ActionMode Helper.
  • FastScroller.
  • ...and more.

The idea behind is to avoid to create from scratch over again a custom Adapter for every project and to have more functionalities in one library, instead of relying on different libraries that support only 1 or 3 of them and that you cannot merge.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please review this post: How to offer personal open-source libraries?? You seem to be posting about your library in various places without tailoring your answer to the context.
Ok I've read it. I always try to stay on the context, but indeed, previous comments said that the solution proposed doesn't work. So, that's why I proposed my library.
5

public void onScrolled(int dx, int dy)

those are the two arguments that you're receiving onScrolled, that means, the number of pixels that the RecyclerView changed on the X and Y axis... so probably all you want to do is:

@Override public void onScrolled(int dx, int dy) { if(dx < 0) // going up showSitckyHeader(); } 

you can probably further improve this implementation by adding a minimum scroll amount. Something like:

int totalScrolled = 0; @Override public void onScrolled(int dx, int dy) { totalScrolled += dx; if(totalScrolled < MIN_SCROLL) showSitckyHeader(); if(dx > 0) totalScrolled = 0; } @Override public void onScrollStateChanged(int newState) { if(newState == SCROLL_STATE_IDLE || newState = SCROLL_STATE_SETTLING) totalScrolled = 0; } 

or even go further and implement speed, counting time, but those types of implementation are more tricky, and you have to test it yourself.

12 Comments

Thanks for the direction.I will give try with your approach but concerns are when recycleview is scrolling up I have to find which item is at top and then I have to find header view in that Item and set margin to that or is there any better way?
what I understand by "sticky header" is that the header can be show at any time when the user scroll up. That means the actual header is not part of the RecyclerView view, but it's in a FrameLayout with the Header and the RecyclerView inside it. The first view on RecyclerView will be an empty view with the same size as the header. And you simply animate/move the header up and down whenever the list moves up and down. A useful method for that is developer.android.com/reference/android/view/… don't use the Margins for that effect.
No.. you are getting me wrong.. I want sticky header like Instagram where each row has one headerview wich sticks at the top till that item dont get scrolled up...
so yeah, I believe you'll have to do something similar to what you suggest on the your previous comment. Find first view, etc.
@Budius but, coordinator layout is only sticky to the first item na, If I want some of the item to be sticky when I scroll the RecyclerView, then how do I do that?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.