Gmail like progress bar in Android

Download Code

Progress bar is pretty simple to implement like what you see in Gmail application.
Follow simple steps below to get it done.

Step 1:
Find progress bar images such as progressbar_indeterminate_holo inside Android Setup\android-sdks\platforms\android-16\data\res\drawable-hdpi and put it inside drawable-hdpi folder

Step 2:
Create progress_bar.xml which includes all sequence images of progressbar_indeterminate_holo.

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myprogress"
    android:oneshot="false" >
 
    <item
        android:drawable="@drawable/progressbar_indeterminate_holo1"
        android:duration="50"/>
    <item
        android:drawable="@drawable/progressbar_indeterminate_holo2"
        android:duration="50"/>
    <item
        android:drawable="@drawable/progressbar_indeterminate_holo3"
        android:duration="50"/>
    <item
        android:drawable="@drawable/progressbar_indeterminate_holo4"
        android:duration="50"/>
    <item
        android:drawable="@drawable/progressbar_indeterminate_holo5"
        android:duration="50"/>
    <item
        android:drawable="@drawable/progressbar_indeterminate_holo6"
        android:duration="50"/>
    <item
        android:drawable="@drawable/progressbar_indeterminate_holo7"
        android:duration="50"/>
    <item
        android:drawable="@drawable/progressbar_indeterminate_holo8"
        android:duration="50"/>
 
</animation-list>

Step 3:
Create main.xml layout and set android:src=”@drawable/progress_bar” to ImageView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@android:color/white" >
 
    <ImageView
        android:id="@+id/imgProgress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:src="@drawable/progress_bar" />
 
</LinearLayout>

Step 4:
Create MainActivity class and initialize above layout

package com.supportmania.gmailprogressbar;

import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView progress = (ImageView)findViewById(R.id.imgProgress);
        if (progress != null) {
            AnimationDrawable frameAnimation = (AnimationDrawable) progress.getDrawable();
            frameAnimation.setCallback(progress);
            frameAnimation.setVisible(true, true);
            frameAnimation.start();
        }
    }
}

 

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of