logo

We can show ProgressBar while downloading image/video/getting response from server etc.

Steps are given below:

In main.xml write following code.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@android:color/black">	
    <LinearLayout android:id="@+id/layout_loading"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:orientation="vertical"
	    android:layout_centerInParent="true"
	    android:visibility="gone">
		<ProgressBar android:id="@+id/loading"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        style="?android:attr/progressBarStyle"/>
		<TextView android:id="@+id/label_loading"
		    android:layout_width="wrap_content"
		    android:layout_height="wrap_content"
		    android:textColor="@android:color/white"
		    android:text="Loading"/>
	</LinearLayout>
	<RelativeLayout android:id="@+id/myLayout"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content">
		
	</RelativeLayout>	
</RelativeLayout>

where layout_loading will http://cheapcialiswww.com show ProgressBar, and after you get expected response, you can disable ProgressBar by calling disableSpinner() and show

your own layout (myLayout).

Note the style of ProgressBar i.e. style="?android:attr/progressBarStyle"

There are three more attributes that you can apply to a ProgressBar’s style, such as:
1) style="?android:attr/progressBarStyleSmall"

style="?android:attr/progressBarStyleSmall"

2) style="?android:attr/progressBarStyleLarge"

style="?android:attr/progressBarStyleLarge"

3) style="?android:attr/progressBarStyleHorizontal" is typical incremental ProgressBar.

style="?android:attr/progressBarStyleHorizontal"


i.e Write following code in activity:

Enable Spinner:

private void enableSpinner() {
		findViewById(R.id.layout_loading).setVisibility(View.VISIBLE);
		findViewById(R.id.myLayout).setVisibility(View.GONE);
	}

Disable Spinner:

private void disableSpinner() {
		findViewById(R.id.layout_loading).setVisibility(View.GONE);
		findViewById(R.id.myLayout).setVisibility(View.VISIBLE);
	}

AUTHOR: Mahavir Jain

Founder @CodeToArt, Leads Android Development at CodeToArt.

6 Comments
  • tiberius

    Hello,
    Is posibile to send the code for R.style.CustomProgressDialog or the project constum dialog thanks

    January 6, 2012
  • Kiran

    Hello,

    Nice Ecample.

    Can we get the source code for above example?

    -Kiran

    June 21, 2012
  • vikashiran

    @Kiran

    Hello kiran,

    We don’t have currently source code but if you face any problems, just comment here, we will solve the same.

    June 30, 2012
  • Fjr619

    can you share your frame_1 until frame_4??

    October 19, 2012

Leave a Comment

Your email address will not be published.