android spin / continuously rotate an image untill

2019-08-26 01:37发布

问题:

I want to make a little fresh icon.

When I click on it, I want it to spin like a progress dialog, until my refresh is completed, then it must stop spinning.

How can I achieve this?

I tried with an animation like so:

RotateAnimation rotateAnimation = new RotateAnimation(30, 90,
                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);                
            refreshBtn.startAnimation(rotateAnimation);

but that only rotates once or twice and then stops.

回答1:

Try this:

RotateAnimation rotateAnimation = new RotateAnimation(30, 90,
                        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setRepeatCount(Animation.INFINITE);
rotateAnimation.setRepeatMode(Animation.RESTART);
refreshBtn.startAnimation(rotateAnimation);