android中rotateanimation怎么应用
在Android中,可以使用RotateAnimation类来实现旋转动画。以下是一个简单的示例代码演示如何应用RotateAnimation:
- 首先,在res/anim文件夹下创建一个rotate.xml文件,定义旋转动画的属性:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:repeatCount="infinite" />
- 在需要应用旋转动画的View中添加如下代码:
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
view.startAnimation(animation);
其中,this是当前Activity的实例,view是要应用旋转动画的View。
这样就可以在View上应用旋转动画了。rotate.xml文件中定义了一个从0度到360度无限循环的旋转动画,可以根据需求修改旋转的角度、中心点、持续时间等属性。
相关问答