We have seen the implementation of Content Placeholder Animation using Shimmer in Android for a simple view. In this article, we will take a look at implementing Content Placeholder Animation using Shimmer in Android with RecyclerView.
What we are going to build in this article?
We will be building a simple application in which we will be simply displaying data in our Android RecyclerView from our API. For the purpose of loading data, we will be displaying a content placeholder for the purpose of loading. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Adding dependency for using Facebook Shimmer layout
Navigate to the app > Gradle Scripts > build.gradle file and add the below dependency to it.
// below line is used for volley library
// below line is used for image loading library
// depenancy for using facebook shimmer layout.
Now sync your project and move towards your XML file.
Step 3: Adding permissions for the internet in Android
Navigate to the app > AndroidManifest.xml and add permissions to it for the internet as we are loading data from the internet.
Step 4: Creating a modal class for storing our data
Navigate to the app > java > your app’s package name > Right-click on it > New > Java class and name it as CourseModal and add the below code to it.
Step 5: Creating a layout file for the item of our RecyclerView in Android
Navigate to the app > res > layout > Right-click on it > New > layout resource file and name it as course_rv_item and add the below code to it.
Step 6: Creating a layout file for our shimmer layout
Navigate to the app > res > layout > Right-click on it > New > layout resource file and name it as shimmer_layout and add the below code to it.
Step 7: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
Step 8: Creating an Adapter class for setting data to our item of RecyclerView
Navigate to the app > java > your app’s package name > Right-click on it > New > Java class and name it as CourseRVAdapter and add the below code to it. Comments are added inside the code to understand the code in more detail.
Step 9: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Now run your app and see the output of the app.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.