Complexities and animations with one of Android’s most important classes

Mustufa Ansari
Aug 5 · 3 min read
Photo by Matam Jaswanth on Unsplash

Initial Setup and Basic Animation

You are going to need the following dependencies in order to make this project.

As you know, I work on Android data binding so let's enable it by adding the following lines of code in our app.gradle file.

dataBinding{
enabled true
}

Hope you are all set! Now let's make a layout that will be responsible for holding each row of RecyclerView — like this.

Create item_list.xml in your layout folder.

Now let's make a model class. As you can see, I’m showing a list of different people with their name, image, and placeholder description (in lorem ipsum text). Each item of RecyclerView holds a single object of Person.java. These objects are created by a model class that I created with the name Person.java.

It’s time to make RecyclerAdapter because RecyclerView needs an adapter to perform its whole functionality. I have created a class called RecyclerAnimationAdapter.java and inherited it from RecyclerView.Adapter.
Add the following lines of code in your project.

Before going any further, let's try to run our app and see what we have done so far. To make it run, we require some data to populate our RecyclerView. For this, I’ve created some dummy arrays. Create array.xml inside your res/values.

people_images are dummy images that I have included in my project. You can have pictures of your own choice.

I am generating data using the following code in your MainActivity.xml .

Your activity_main.xml should look like this.

Let's run the app and see if everything is working fine up till now.

Made good progress? Now everything is working fine. It’s time to introduce animations in our RecyclerView.


Fade-In Animation

I’m making fade-in animation first. All you need to is to add the following lines of code in your project.

setAnimation() is responsible for making animation in RecyclerView.

AnimatorSet()This class works like an array that takes different animations and makes them play.

ObjectAnimator(): This class performs different animations.

Let’s run the app!

Items are loading with a fade-in effect! Let’s introduce some more effects.


Left-to-Right Animation

In order to make items enter from left to right, let’s add following to your code.

Make sure to update your DURATION to equal 150.


Right-to-Left Animation

To animate right to left, use the following code.


Done! I hope you enjoyed the tutorial. Thank you so very much for your time. Happy coding!

Better Programming

Advice for programmers.

Mustufa Ansari

Written by

📱Mobile Application Developer 🎓Keen Learner 🎓Graduate 🎧Love Music 🎓 Tech Enthusiast!

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade