Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make default Android loader animation? [closed]

I want to make an Android "busy" animation, with similar image to default.

Like this:

enter image description here

like image 978
sztembi Avatar asked Nov 14 '11 12:11

sztembi


2 Answers

If you need something like this in your Android application, you can use a ProgressBar. It offers a setIndeterminate()-method which makes it display an infinite spinning circle (like the one in your example).

If another drawable is needed, you can use the setIndeterminateDrawable()-method.

If you just want an animated image of this spinning circle (e.g. for your Ajax loading-process), you can find one here: http://www.ajaxload.info/

like image 108
Lukas Knuth Avatar answered Nov 04 '22 09:11

Lukas Knuth


Just use a static image and rotate it. This will give you the desired effect.

ImageView image = (ImageView) findViewById(R.id.refreshicon);

float ROTATE_FROM = 0.0f; // from what position you want to rotate it
float ROTATE_TO = 10.0f * 360.0f; // how many times you want it to rotate in one 'animation' (in this example you want to fully rotate -360 degrees- it 10 times)

RotateAnimation r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
r.setDuration(7500); // here you determine how fast you want the image to rotate
r.setRepeatCount(Animation.INFINITE); // how many times you want to repeat the animation
r.setInterpolator(new LinearInterpolator()); // the curve of the animation; use LinearInterpolator to keep a consistent speed all the way

image.startAnimation(r);
like image 42
Reinier Avatar answered Nov 04 '22 09:11

Reinier