Recycler View Animation - 3

As we already talked about Slide From Bottom animation and Fall Down Animation in recycler View. Now we are going to know about another type of animation in recycler view Slide From Right Animation.

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 : 

2. Fall Down
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 Right 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 Right Animation 

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_right_animation (You can take any name you want for this android resource file). 

In this slide_from_right_animation file put the following code given below :

slide_from_right_animation.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="600">

    <translate
        android:fromXDelta="100%p"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:toYDelta="0"/>

    <alpha android:fromAlpha="0.5"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toAlpha="1"/>

</set>


Step 3

After creating slide_from_right_animation.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_right.


In this layout_animation_slide_from_right file put the following code given below :

layout_animation_slide_from_right.xml

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

Step 4

After Doing all this put this layout_animation_slide_from_right 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_right"

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_right"/>

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.