Skip to content

spun/android-recyclerview-playground

Repository files navigation

android-recyclerview-playground

Shared element

Between Activities

[ Grid | Detail ]

Simple example of how to share an element between two activities + RecyclerView.

The GridActivity RecyclerView is able to scroll to position if the element is hidden.

📝 TO-DO: Add a ViewPager to the detail activity to show this behavior in a better way.

Between Fragments (Navigation component)

[ Grid | Detail ]

Same example as before but using the navigation component from jetpack and material components.


Item selection

[ Grid ]

References:


Fixed header decoration

[ ItemDecoration ]

References:


Auto scroll

"Lock" the scroll of a RecyclerView to the Top/Bottom so we can see when new items are added.

Item insert

New items inserted to the end of the RecyclerView are (by default) not visible until we scroll. Same behaviour if we add items to the start of the list.

Solution (chat app behaviour): We can use a RecyclerView.AdapterDataObserver to receive "onItemRangeInserted" events and scroll automatically if some conditions are met (if we are inserting an item (or items) to the end of the list and if the user was already looking at the end).

[ ScrollToTop | ScrollToBottom ]

Item position changes

If we have an ordered list (i.e.: green on top) and the order of items changes, the RecyclerView can scroll to keep visible the item it considers important. Depending on the needs of your app, it might appear as if the RecyclerView is scrolling when it shouldn't and can cause confusion to the users.

Solution (don't move too much): We can use the same RecyclerView.AdapterDataObserver to receive "onItemRangeMoved" events and keep the scroll where it was.

[ ScrollToTopPlus ]


Images made by Freepik from www.flaticon.com

Releases

No releases published

Packages

No packages published