Set the progress bar on top of the RecylerView and delete it after loading the data

I want to have a download icon displayed on top of where the RecyclerView will be, and disappear when the data download is complete.

It will look like this:

enter image description here

Can anyone help me out?

I have a code that shows a TextView over a RecyclerView that says β€œLoading ...” and disappears after loading the data, but the RecyclerView is still showing.

My XML:

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/loaderTV" android:text="Loading..." android:layout_above="@+id/eventListRV"/> <android.support.v7.widget.RecyclerView android:scrollbars="vertical" android:id="@+id/eventListRV" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/spinner"> </android.support.v7.widget.RecyclerView> 

And then in my code

 client.listCreators(request, new Callback<ServiceResponse<Event>>() { @Override public void success(ServiceResponse<Event> eventServiceResponse, Response response) { eventList.addAll(eventServiceResponse.data.results); Log.i("tag", String.valueOf(eventServiceResponse.data.total)); if (eventList.size() > 60) { adapter.notifyDataSetChanged(); loadingText.setVisibility(View.GONE); } } 

But I want the RecyclerView to be invisible during data loading, and I want the progress bar to be on, where the RecyclerView is, and I don't want it to be a textview

+6
source share
4 answers
  • Wrap both your RecyclerView and your loading layout (or TextView) inside a FrameLayout. Set both values ​​to match_parent for width and height.
  • Hide RecyclerView in onCreate () of your activity or onCreateView () of your fragment: recyclerView.setVisibility(View.GONE);
  • In the callback method, setVisibility(View.GONE) download layout setVisibility(View.GONE) , show your RecyclerView with setVisibility(View.VISIBLE) and restart the adapter using adapter.notifyDataSetChanged()
+14
source

To scale the size of the progress bar, you can use scaleX and scaleY and adjust the value to a 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> 
+2
source

To center the user in the "Progress" line, use

 android:layout_centerVertical="true" android:layout_centerHorizontal="true" 
+1
source

Recycler View.

  1. Use RelativeLayout . Prepare the ProgressBar using 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. On MainViewAdapter extends RecyclerView.Adapter<MainViewAdapter.MyViewHolder>

in 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); } 
0
source

Source: https://habr.com/ru/post/1214505/


All Articles