android spin / continuously rotate an image untill

2019-08-26 01:48发布

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条回答
Melony?
2楼-- · 2019-08-26 02:07

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);
查看更多
登录 后发表回答