在程序开发中有时候需要让某一个空间旋转一定角度,或者是无限旋转(类似Progressbar)。
其实实现起来也很简单:
RotateAnimation mFlipAnimation; mFlipAnimation = new RotateAnimation(0, 45, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); mFlipAnimation.setInterpolator(new LinearInterpolator()); mFlipAnimation.setDuration(80);//如果参数是0,就是无限旋转 mFlipAnimation.setFillAfter(true);
然后就是控件的操作:
your_button.clearAnimation(); your_button.startAnimation(mFlipAnimation);
我实现的效果是你点击的你的button,然后你的button就会旋转45度。