XML codes for Layout file
First, include these codes to your activity layout XML file.
FrameLayout is used as it can be on top (overlay) other layout components.
The background of the FrameLayout is set to Android default background color. You can change it to any color you want, or even transparent.
Progress bar (circular spinner) is for showing the animation. Layout gravity set to center to make it center on the page.
<FrameLayout
android : id =" @+id/loadingFrame"
android : layout_width =" match_parent"
android : layout_height =" match_parent"
android : background =" ?android:attr/colorBackground"
android : visibility =" gone" >
<ProgressBar
android : id =" @+id/progressBar"
style =" ?android:attr/progressBarStyle"
android : layout_width =" 106dp"
android : layout_height =" 107dp"
android : layout_gravity =" center" />
</FrameLayout >
Then, in your activity, define the FrameLayout component.
final FrameLayout loadingFrame = (FrameLayout ) findViewById (R .id .loadingFrame );
Finally, use setVisibility() to set component to VISIBLE
to display the progress bar, or GONE
to hide it.
// show
loadingFrame .setVisibility (View .VISIBLE );
// hide
loadingFrame .setVisibility (View .GONE );
Afif Zafri
Used for my fyp project, save for future references and share with others