Recyclerview right now has 3 states.
SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING, SCROLL_STATE_SETTLING
An issue raised for the same to include a fling state.I cannot determine if anything was done regarding this.
Is there a way to differentiate between a Drag and a Fling in recyclerview.
EDIT: The requirement for such functionality: When the user flings,I want to be able to pause loading images(all images are url requests) in the recycler view and resume once he reaches an item of interest,thereby ensuring that the image he is currently viewing loads before the others.
SCROLL_STATE_FLING
: No longer a part of RecyclerView
as it is not mentioned in documentation here
Regarding your requirement :
RecyclerView is inside android.view.ViewGroup
and as per its source code it extends ViewGroup
documentation here .
The scrolling in a RecyclerView is sort of split up between the RecyclerView and the LinearLayoutManager. There are two cases that needed to handle:
fling()
implementation and instead of flinging
, smoothscroll
the LinearLayoutManager
to a position.onTouchEvent
method.See here for detail Snappy scrolling in RecyclerView
A few ViewPager
hints that are worth mentioning as RecyclerView
is a child of it:
Think about modifying the number of pages that are cached. This is especially important when you only have 3 or 4 pages. The default setting will store 1 page either side of the current page. In the scenario that you have 3 pages, swiping to the middle page will mean that all of your pages will be cached. Then swiping to the first or last page will drop one of the pages out of memory and they will need to be recreated and re-added when you swipe back again. By setting setOffscreenPageLimit(2)
you’ll allow all of your pages to stay in memory all the time. This is a trade off between performance and memory considerations, so it is a good idea to listen for low memory warnings and be prepared to remove edge pages if necessary.
If you’re trying to replace Views in your ViewPager, it isn’t enough just to change the data set behind the adapter and call notifyDataSetChanged()
. You also need to ensure that you’ve correctly implemented getItemPosition(Object object)
and return POSITION_NONE
for items that have changed and return POSITION_UNCHANGED
or the actual position for items that haven’t changed.
Another API that was added is setPageMargin()
and setPageMarginDrawable()
, allowing you to easily separate your pages.
See here for detail Horizontal View Swiping with ViewPager, Updated
Difference between a Drag and a Fling
For Drag feature You can use some of the RecyclerView's
companion classes:
ItemTouchHelper, which is a utility class to add swipe to dismiss and drag & drop support to RecyclerView.
its ItemTouchHelper.Callback, which is the contract between ItemTouchHelper and your application
For fling you can see
Android fling actions on a RecyclerView
Android : Control Smooth scroll over recycler view
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With