Before displaying the required fragment, I would like to show the loading screen (without Dialog ) until the data has been loaded. The difficulty is that it needs to be implemented as a fragment, in whose place the data will already be displayed. Only crutches come to mind. When googled, stumbled upon this library:

https://github.com/johnkil/Android-ProgressFragment

But it has not been updated for a long time, and I don’t want to clog the project with libraries either. Perhaps someone knows the optimal way to get this effect?

Thank you in advance.

UPD

Perhaps not entirely obvious, but I want to get a similar effect.

enter image description here

  • one
    Why invent a crutch with a boot fragment, if you can just show the progress bar, and when everything loads show the layout - Sviat Volkov
  • @SviatVolkov showing Dialog means blocking control. Yes, and does not look very much. I just want to show an empty fragment with a boot circle (it sounds stupid) in the center to show the main markup. - ahgpoug
  • @ahgpoug, The progress bar can be shown in the main markup, without dialogue. - post_zeew
  • you just do a FrameLayout in which your main layout and progress bar lies. when the layout is loading at visibility = gone when loaded, set visible. no need for dialogue. Dialogues in general for another were invented - Sviat Volkov

1 answer 1

You place in the fragment a progress bar and a container with content that is initially hidden:

 <?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"> <ProgressBar android:id="@+id/loading_progress_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/> <FrameLayout android:id="@+id/content_frame_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"> </FrameLayout> </FrameLayout> 

When the data is loaded, hide the progress bar and show the container with the data.

  • The problem is that in my case CoordinatorLayout used with CollapsingToolbarLayout . I cannot assign it to the container. In general, I now have these crutches: when downloading a fragment, I check the factors: network connectivity and data availability. Before the inflater.inflate method inflater.inflate I check this all out and then pass the necessary markup to the inflater . Here at the moment when the markup has not yet been assigned, but the download has not yet completed, I need to show the ProgressBar . While vaguely imagine how to do it. - ahgpoug
  • @ahgpoug, Назначить его в контейнер я не могу assign Назначить его в контейнер я не могу - Why? In any case, you can stuff a progress bar somewhere. - post_zeew
  • As I read, CoordinatorLayout does not work well with containers. After I assigned it to the second FrameLayout , it was rendered crooked. - ahgpoug
  • Already solved my problem. Instead of using FrameLayout , include . Included all 3 fragments in one layout and make visible the one that fits the conditions. Thanks for the tip. - ahgpoug