根据下面的代码(我在 Android: Rotate image in imageview by an angle ) 我制作了一个动画xml并为其设置了持续时间。
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="45" android:toDegrees="45" android:pivotX="50%" android:pivotY="50%" android:duration="0" android:startOffset="0" />
那么,我应该如何将这个随机数(我在主要活动中获得)放入动画xml的持续时间中呢?
使用 setDuration
Animation animation = AnimationUtils.loadAnimation(context, R.anim.your_animation); animation.setDuration(300); view.startAnimation(animation);