0

i want to create a progressbar in android like that image

enter image description here

i try to use

<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loadingicon"
android:pivotX="50%"
android:pivotY="50%" />

but i think it not meet in my requirement

Atif Farrukh
  • 2,219
  • 2
  • 25
  • 47
Pham Hong Phong
  • 145
  • 2
  • 10
  • Easiest solution is probably to deconstruct the gif animation into its separate frames and create an [`AnimationDrawable`](http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html) (where every `` points to a frame). – MH. Jun 04 '13 at 08:20

2 Answers2

7

Here is a good example to customize progressbar: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

U must draw all state of you future progress bar (img1.png, img2.png, img3.png, img4.png). put image to /res/drawable.

pb_animation.xml:

<animation-list android:id="@+id/myprogressrbar" android:oneshot="false">
  <item android:drawable="@drawable/img1" android:duration="50" />
  <item android:drawable="@drawable/img2" android:duration="50" />
  <item android:drawable="@drawable/img3" android:duration="50" />
  <item android:drawable="@drawable/img4" android:duration="50" />
</animation-list>

And then, in yor code:

 ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
 img.setBackgroundResource(R.drawable.pb_animation);
 AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
 frameAnimation.start();
Ivan Podhornyi
  • 779
  • 3
  • 7
  • 17
1

you could use an AnimationDrawable in combination with an ImageView and add a drawable for every state of your loading indicator, but a better way to this, is creating a new Style for a ProgressBar view (by extending de platform default style) and use your AnimationDrawable as loading indicator.

The Android styles are open source, so you can easily find them and extend them for your needs.

Good luck!

Cliffus
  • 1,481
  • 2
  • 11
  • 7
  • I tried this approximation wich worked perfectly and clean by just applying styles to the progressbar – Raykud Jul 08 '13 at 21:58