RecylerView Animation - Androhub

RecyclerView Animation Banner

RecylerView Animation

In earlier tutorials we had learned implementation of RecyclerView. Now in this tutorial we will move to RecyclerView Animation part. The best thing of RecyclerView is that it provide inbuilt animations but the ListView and GridView don’t provide inbuilt animation. Now to implement the Animation in RecyclerView it provide some methods that we need to use:

  1. notifyItemRemoved(position) : While removing item from RecyclerView we need to call this method, this method will remove the item from particular position with animation.
  2. notifyItemInserted(position) : If you want to insert item then you need to call this method, this method will insert the item at particular position with animation.
  3. notifyItemChanged(position) : When you want to change row item with any other item then you need to call this method, this method will change the item at particular position.

Example

In this tutorial, we are going to learn how to use implement RecyclerView Animation.

VIDEO DEMO

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. By default my activity is MainActivity.java.

2. Open strings.xml located under res=>values folder and add following strings.

3. Open your build.gradle file and below dependency to it.

4. Create activity_main.xml and add the following code. In this xml file Toolbar is taken in place of ActionBar and 3 RadioButtons to do three operations on RecyclerView and finally take RecyclerView.

If you are new to RecyclerView visit my RecyclerView tutorial.

5. Now for RecyclerView item row create list_item_row.xml and add views according to your requirement.

6. Open your MainActivity.java and the following code to it. In this class we are adding items to RecyclerView and handling RadioButton functionality.

7. Finally create RecyclerView_Adapter.java class and add the following code to it. Below are some methods that are used to operate RecyclerView:

  • Delete Item

  • Insert Item

  • Change Item

Now add all these methods to RecyclerView adapter.

Here the clickType is to check which RadioButton is selected for changing its value a method is created:

8. Finally, all done – now you add Animation to your RecyclerView..

Thanks. 🙂

 

Post comment

Your email address will not be published. Required fields are marked *