- RecyclerView automatically scrolls to the bottom when data is loaded the first time because of call to notifyItemInserted(index). #886
- Comments
- muddassir235 commented Sep 3, 2017 •
- SUPERCILEX commented Sep 3, 2017
- muddassir235 commented Sep 3, 2017
- muddassir235 commented Sep 3, 2017 •
- muddassir235 commented Sep 3, 2017 •
- muddassir235 commented Sep 3, 2017 •
- muddassir235 commented Sep 3, 2017 •
- muddassir235 commented Sep 3, 2017
- SUPERCILEX commented Sep 3, 2017
- muddassir235 commented Sep 3, 2017
- samtstern commented Sep 5, 2017
- viramaham73 commented Jun 6, 2018
- Roxytsai commented Jul 28, 2018
- alextfos commented Aug 26, 2018
- hitenpannu commented Nov 10, 2018
- egorikem commented Nov 12, 2018
- TonyTangAndroid commented Nov 21, 2018
- salmankhalid876 commented Jan 28, 2020
- Harsh0021 commented Jun 7, 2020
- Fast Scrolling with RecyclerView
RecyclerView automatically scrolls to the bottom when data is loaded the first time because of call to notifyItemInserted(index). #886
Comments
muddassir235 commented Sep 3, 2017 •
I was trying to implement a vertical recyclerview laid out from top to bottom with a firebase node as a data source. I implemented it, but when the data got loaded the list always scrolled to the bottom. I looked into the FirebaseUIDatabase code and discovered the following calls.
In a top to bottom layout this isn’t desired.
I have implemented a solution for this and wanted to share my code.
The mClipTopFirstTime variable, if true initially, would allow children to be added without scrolling to them. After a certain delay it would be set to false, afterwards, the default behaviour of scrolling to newly added children would be restored.
Should I make a pull request?
The text was updated successfully, but these errors were encountered:
SUPERCILEX commented Sep 3, 2017
No, there’s something else wrong with your code: by default, the recyclerview doesn’t scroll when new items are added. 😕 Did you copy the sample app code? It auto scrolls to the bottom because it’s a chat app:
Lines 129 to 135 in 1e179c0
// Scroll to bottom on new messages |
mAdapter . registerAdapterDataObserver( new RecyclerView . AdapterDataObserver () < |
@Override |
public void onItemRangeInserted ( int positionStart , int itemCount ) < |
mManager . smoothScrollToPosition(mMessages, null , mAdapter . getItemCount()); |
> |
>); |
Hope this helps! 😃
muddassir235 commented Sep 3, 2017
I didn’t copy this code 😛
muddassir235 commented Sep 3, 2017 •
muddassir235 commented Sep 3, 2017 •
muddassir235 commented Sep 3, 2017 •
muddassir235 commented Sep 3, 2017 •
muddassir235 commented Sep 3, 2017
Maybe read from bottom to Top 😛 or as you like 😛
SUPERCILEX commented Sep 3, 2017
@muddassir235 Nothing caught my eye right away so this kind of thing should probably be posted on Stack Overflow. However, you can check a few things: do you have the LinearLayoutManager reverse its order somewhere? Are views at the bottom of the recyclerview requesting focus? Are you doing something funky in XML? Are you using an old version of the support lib (latest is 26.0.1 )?
This kind of thing is difficult to debug because there’s so much code and non-conventional stuff going on. I would recommend saving your current code in a dev branch somewhere and then ripping everything out until you’re left with only a fragment and the raw FirebaseRecyclerAdapter with just bind view overridden. If that doesn’t work, then something has gone terribly wrong somewhere else.
muddassir235 commented Sep 3, 2017
OK, will try that.
samtstern commented Sep 5, 2017
@muddassir235 I agree with @SUPERCILEX. This type of issue should be posted on StackOverflow since it is not caused by FirebaseUI but rather something in your a[[‘s code. Good luck!
viramaham73 commented Jun 6, 2018
please use this code
Hope this helps
Roxytsai commented Jul 28, 2018
@muddassir235
Hi, I have the same situation. Do you find solution?
alextfos commented Aug 26, 2018
Hi @Roxytsai, the solution proposed by @viramaham worked for me.
hitenpannu commented Nov 10, 2018
If this is happening when you are changing the visibility of the recycler view. The issue might be of focus. Try adding a dummy edit text view before recycler view and give 0 width and 0 height to it. Also set focusable to true for this editText and set focusable to false for recycler view
egorikem commented Nov 12, 2018
Although solution provided by @viramaham does work, it does not address situation where stackFromEnd = true is used: issue still presents
TonyTangAndroid commented Nov 21, 2018
No, there’s something else wrong with your code: by default, the recyclerview doesn’t scroll when new items are added. 😕 Did you copy the sample app code? It auto scrolls to the bottom because it’s a chat app:
FirebaseUI-Android/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java
Lines 129 to 135 in 1e179c0
// Scroll to bottom on new messages
mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() <
@OverRide
public void onItemRangeInserted(int positionStart, int itemCount) <
mManager.smoothScrollToPosition(mMessages, null, mAdapter.getItemCount());
>
>);
Hope this helps! 😃
For those who want to have a better clue of what’s going on here, please refer to this issue in epoxy repo. airbnb/epoxy#224 (comment).
It has quite elaborated explanation on why and how.
salmankhalid876 commented Jan 28, 2020
@muddassir235 Nothing caught my eye right away so this kind of thing should probably be posted on Stack Overflow. However, you can check a few things: do you have the LinearLayoutManager reverse its order somewhere? Are views at the bottom of the recyclerview requesting focus? Are you doing something funky in XML? Are you using an old version of the support lib (latest is 26.0.1 )?
This kind of thing is difficult to debug because there’s so much code and non-conventional stuff going on. I would recommend saving your current code in a dev branch somewhere and then ripping everything out until you’re left with only a fragment and the raw FirebaseRecyclerAdapter with just bind view overridden. If that doesn’t work, then something has gone terribly wrong somewhere else.
Harsh0021 commented Jun 7, 2020
No, there’s something else wrong with your code: by default, the recyclerview doesn’t scroll when new items are added. 😕 Did you copy the sample app code? It auto scrolls to the bottom because it’s a chat app:
Источник
Fast Scrolling with RecyclerView
Aug 26, 2017 · 3 min read
Continuing with Support Library 26 features (if you missed the one with downloadable fonts), a much awaited feature was enabled : fast scrolling for RecyclerView.
Of all the great advantages RecyclerView has over ListView, one feature that I miss a lot is fast scrolling where you could drag a thumb drawable and scroll around the list. In ListView you could do the following :
But with RecyclerView, there is no easy way to have a thumb drawable like so :
So we would rely on libraries like this and this.
With Suppo r t Library 26, we can easily enable fast scrolling for RecyclerView. Let’s get to it!
Let’s make sure we’re getting the Support Library 26. The app build.gradle file will look something like :
Since Support Library 26 has now been moved to Google’s maven repository, let’s include that in our project level build.gradle
This is what our layout file for the activity looks like :
I have setup a simple RecyclerView filled with mock data that shows US states and their state code. It looks something like :
Now let’s enable the fast scrolling. The updated xml file looks like :
Let’s go over each property one by one :
- fastScrollEnabled : boolean value to enable the fast scrolling. Setting this as true will require that we provide the following four properties.
- fastScrollHorizontalThumbDrawable : A StateListDrawable that will be used to draw the thumb which will be draggable across the horizontal axis.
- fastScrollHorizontalTrackDrawable : A StateListDrawable that will be used to draw the line that will represent the scrollbar on horizontal axis.
- fastScrollVerticalThumbDrawable : A StateListDrawable that will be used to draw the thumb which will be draggable on vertical axis.
- fastScrollVerticalTrackDrawable : A StateListDrawable that will be used to draw the line that will represent the scrollbar on vertical axis.
Let’s look at the StateListDrawables. I’ve used native shapes so that you can easily reuse them.
Источник