Open In App

How to Add Fade and Shrink Animation in RecyclerView in Android?

Last Updated : 12 Apr, 2021
Like Article

In this article, we are going to show the fade and shrink animation in RecyclerView. When we move downward then the item at the top will be fading out and then it will shrink. In the output, we can see how it is happening. We will be implementing this Java programming 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: Add this into build.gradle file

implementation 'com.stone.vega.library:VegaLayoutManager:1.0.6'

Step 3: Working with the items.xml file

Go to the app > res > layout > New > Layout Resource File and name the file as item. Go to the item.xml file and refer to the following code. Below is the code for the item.xml file.


<?xml version="1.0" encoding="utf-8"?>
        android:text="Click Here" />

Step 4: Working with the file

Create a new java class in android studio and name the class as RecyclerViewAdapter. Go to the file and refer to the following code. Below is the code for the file. 


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
    private int mcount;
    public RecyclerViewAdapter(int mcount) {
        this.mcount = mcount;
    public RecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items, parent, false);
        return new ViewHolder(view);
    public void onBindViewHolder(@NonNull final RecyclerViewAdapter.ViewHolder holder, final int position) {
        holder.itemclick.setText("Button" + position);
        holder.itemclick.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(holder.itemView.getContext(), "Clicked : " + position, Toast.LENGTH_LONG).show();
    public int getItemCount() {
        return mcount;
    public class ViewHolder extends RecyclerView.ViewHolder {
        Button itemclick;
        public ViewHolder(@NonNull View itemView) {
            itemclick = itemView.findViewById(;

Step 5: 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. 


<?xml version="1.0" encoding="utf-8"?>
        android:layout_height="match_parent" />

Step 6: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import androidx.recyclerview.widget.RecyclerView;
import com.pluscubed.recyclerfastscroll.RecyclerFastScroller;
import com.stone.vega.library.VegaLayoutManager;
public class MainActivity extends AppCompatActivity {
    RecyclerView recyclerView;
    RecyclerFastScroller fastScroller;
    protected void onCreate(Bundle savedInstanceState) {
        recyclerView = findViewById(;
        // We have used this to add fade and shrink method
        recyclerView.setLayoutManager(new VegaLayoutManager());
        recyclerView.setAdapter(new RecyclerViewAdapter(50));


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads