Android - Loading fragment implementation

2019-04-06 07:42发布

问题:

I'd like to start my app and show the main screen instantly. Half of the info on the screen will be loaded form local storage and the other half will be from a web service. Each of these will be on two different fragments. I'd like to display a loading indeterminate progress bar while the data is being fetch from the webservice, similar to how the Google Play Store loads it's app date as shown below by the two states below:

My thoughts on implementing it are as follows:

Load the fragment in with the progress bar & the normal screen (hidden) in one layout. Once the data from the web service has been collected, populate the normal screen, then hide the view group containing the progress bar and show the viewgroup with the data.

Is this best practice? Are the better ways to do it than this?

Thanks in advance.

回答1:

You can implement it yourself but you can also use a simple library called ProgressFragment avalaible on github