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.
Same example as before but using the navigation component from jetpack and material components.
[
Grid
]
References:
- How to Add Multiple Selection to Android RecyclerView from Envato Tuts+
- Android Developers Docs
[
ItemDecoration
]
References:
"Lock" the scroll of a RecyclerView to the Top/Bottom so we can see when new items are added.
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
]
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