Set progress bar on top of RecyclerView and remove after data is loaded

For centering user of Progress bar use

android:layout_centerVertical="true"
android:layout_centerHorizontal="true"

  1. Wrap both your RecyclerView and your loading layout (or TextView) inside a FrameLayout. Set both of them to match_parent for width and height.
  2. Hide the RecyclerView in the onCreate() of your activity or onCreateView() of your fragment: recyclerView.setVisibility(View.GONE);
  3. In your callback method hide the loading layout with setVisibility(View.GONE), show your RecyclerView with setVisibility(View.VISIBLE) and trigger a reload of the adapter with adapter.notifyDataSetChanged()

For scalling the progress bar size you can use scaleX and scaleY and adjust the value for smaller size.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/frameLayout">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ProgressBar
        android:id="@+id/progressBar"
        android:visibility="visible"
        android:scaleX="0.10"
        android:scaleY="0.10"
        android:textColor="@color/colorAccent"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_gravity="center"/>
</FrameLayout>

Recycler View.

  1. Use RelativeLayout. ProgressBar prepare with android:layout_centerInParent="true".

    <ProgressBar
        android:id="@+id/progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
    
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    

  2. At MainViewAdapter extends RecyclerView.Adapter<MainViewAdapter.MyViewHolder>

at onBindViewHolder

 @Override
 public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
 MainItem mainItem = mainItemList.get(position);
 holder.getTextViewTitle().setText(mainItem.getNameMain());

 //all your code here...

 //After that display progressbar at the below
 progressBar.setVisibility(View.GONE);
 }