我的 ImageView 由圆轮组成,如下图所示。我希望该轮子应在用户按下开始按钮时立即开始旋转,并在用户按下停止按钮时停止旋转。是否可以通过编程方式实现?如果是,我该如何做这样做吗?
最佳答案
创建一个名为顺时针旋转.xml的文件并将其放入/res/anim
根据您的需要更改持续时间。
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3500"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:startOffset="0"
android:toDegrees="360"
/>
并创建您将在两个按钮中调用的这两个函数
private void startAnimation(){
Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.clockwise_rotation);
mImageView.startAnimation(rotation);
}
private void stopAnimation(){
mImageView.clearAnimation();
}
关于android - Android 中的旋转轮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29999663/