HK.avdalyan
HK.avdalyan

Reputation: 734

Custom Progress bar or Seekbar or animation?

I need to create some progress bar without dialog like this: enter image description here

I could not find how to create custom progress bar and use it in main activity (not in dialog). This red bar consists of 2 small images and I need to add them continuously while my thread is working. Now What is the way to do it ? Maybe it is better to use animations ? Any idea ? Thanks

Upvotes: 0

Views: 462

Answers (1)

ElDuderino
ElDuderino

Reputation: 3263

There is actually a ProgressBar widget.

<ProgressBar
    android:id="@+id/pb"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_width="match_parent"
    android:layout_height="10dp"
    android:max="100"
    android:progressDrawable="@drawable/progressbar" />

and as progressbar drawable e.g.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@android:id/background">
    <shape>
        <gradient
            android:angle="270"
            android:centerColor="#AA444444"
            android:centerY="0.5"
            android:endColor="#88000000"
            android:startColor="#88000000" />
    </shape>
</item>
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <gradient
                android:angle="270"
                android:centerColor="#FFFFFF44"
                android:centerY="0.5"
                android:endColor="#FFAAAA00"
                android:startColor="#FFAAAA00" />
        </shape>
    </clip>
</item>
<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <gradient
                android:angle="270"
                android:centerColor="#FF88FF88"
                android:centerY="0.5"
                android:endColor="#FF44AA44"
                android:startColor="#FF44AA44" />
        </shape>
    </clip>
</item>

</layer-list>

and for updates from your thread, post a runnable with progressbar.setProgress() or progressBar.setSecondaryProgress(), or even better, use an AsyncTask and call publishProgress and receive the calls in onProgressUpdate()

Upvotes: 1

Related Questions