Recycler View Animation - 1

Adding animation into android application is quite easy. Animation makes our application user interface more elegant and user interactive. There are mainly three types of animation in available in android studio Translation, Rotation and Fading. 

Recycler View Animation are different from these three animations. In recycler view we are going to animate its item. To Animate the item of recycler view there are three types of animation present : 

1. Slide From Bottom
3. Slide From Right

All three animation are shown in the image given below :


Image From Google


In this article we are going to cover Slide From Bottom Animation. Here i am assuming that you already created the recycler view, adapter and and item which we are going to show in this recycler view. 

Now to animate the items of recycler view follow  the steps given below :

Slide From Bottom

Step 1

Create a New Android Resource Directory anim inside your res directory : res\anim

Step 2

Inside this res\anim directory create a new Android Resource File slide_from_bottom (You can take any name you want for this android resource file).

In this slide_from_bottom file put the following code given below :

slide_from_bottom.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="400">
    <translate android:fromYDelta="50%p"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toYDelta="0"/>
    <alpha android:fromAlpha="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toAlpha="1"/>
</set>


Step 3


After creating slide_from_bottom.xml file create another Android Resource File inside res\anim directory. File name you can take anything you want, here i am using name layout_animation_slide_from_bottom.


In this layout_animation_slide_from_bottom file put the following code given below :

layout_animation_slide_from_bottom.xml


<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
     android:animation="@anim/
slide_from_bottom"
    android:animationOrder="normal"
    android:delay="15%">
</layoutAnimation>

Step 4


After Doing all this put this layout_animation_slide_from_bottom file inside your recycler view tag in
activity_main.xml. Put the line given below inside your recycler view tag.

    android:layoutAnimation="@anim/layout_animation_slide_from_bottom"

After putting this line inside your recycler view tag (which is inside your activity_main.xml) your
recycler view will look like this :

activity_main.xml

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="6dp"
    android:layoutAnimation="@anim/layout_animation_slide_from_bottom"/>

Now run your application inside your emulator or mobile phone and check that this animation is working or not. If it is not working then comment us below.