Adding individual view animations for RecyclerView

133 Views Asked by At

I am trying to play around with animations on RecyclerView. Here is the userflow I am trying to achieve

  • I have a horizontal scrollable RecyclerView. When user selects an item, I want all other items to disappear except the one selected.
  • Then I want that selected item to slide to the very first position
  • And I want to show the rest of the items in the recycler view again.

E.g. Given below

Sample Google Chrome behavior

Any help or pointers are greatly appreciated. Thanks

1

There are 1 best solutions below

0
XxGoliathusxX On

I dont know how to do it horizontally but I know how to get the animation. You have to see how you customize it to your requirements:

This tutorial adds drag and swipe behavior to a RecyclerView. We use the animation of it for your purpose. We will do the "drag" (moving the element to the first position not via drag but automatically). For that we use the in the tutorial presented method "swap". And then you should have it.

1 - When an item is selected set all other items on INVISIBLE (NOT GONE!!!)
2 - Use the method swap to move it with an animation to the first position:

public void swap(int from, int to){

            if(to > from){
                for(int i = to; i > from; i--){
                    Collections.swap(mItemList, i, i - 1);
                    notifyItemMoved(i, i - 1);
                }
            }else{
                for(int i = to; i < from; i++){
                    Collections.swap(mItemList, i, i + 1);
                    notifyItemMoved(i, i + 1);
                }
            }
        }

3 - Set the other items on VISIBLE again.