It seems the problem is what you are trying to do. The ListView on top of the progress bar in your layout may have a variable height depending on its contents. Thus, it is not possible to ensure that the progress bar is in the center of the screen using a linear layout.
You can look at the ProgressDialog class, which will show a progress dialog when loading data into a list in the background.
Alternatively, you can overlap the ProgressBar and ListView with RelativeLayout as the top-level layout and specify the android:layout_centerInParent="true"
attribute android:layout_centerInParent="true"
for the ProgressBar
source share