我希望这张照片轻轻旋转

时间:2019-03-29 12:36:50

标签: java android

我已经看过这个问题:基于android中的触摸事件以圆周运动方式移动图像,但这只能告诉我如何沿圆周移动图像,而不是旋转图像。

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试使用此代码旋转图像,希望它是png或某些矢量。

    private fun rotateLoadingAnimation() {
    val rotate = RotateAnimation(0f,
            180f, Animation.RELATIVE_TO_SELF,
            0.5f, Animation.RELATIVE_TO_SELF,
            0.5f)
    rotate.duration = 5000
    rotate.interpolator = LinearInterpolator()
    ivRotating.startAnimation(rotate)
}

答案 1 :(得分:0)

您可以使用clockwise旋转动画在res/anim/clockwiseanim.xml中实现这种旋转形式。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/cycle_interpolator">
    <rotate android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="5000" />
</set>