旋转动画不会在中心点旋转资产

Rotation animation is not spinning the asset in center point

我正在尝试旋转一个圆形按钮,但 pressed.My 问题是按钮没有围绕它自己的中心旋转。遵循其他示例,但结果是相同的。这是我的代码:

rotate.xml:

?xml version="1.0" encoding="utf-8"?>

<rotate
    android:duration="1500"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:repeatMode="restart"
    android:toDegrees="360" />

并且在 class 我正在使用动画:

Animation animRotate = AnimationUtils.loadAnimation(getContext(), R.animator.rotate);

@Override
public boolean onTouchEvent(MotionEvent event) {

Log.e(TAG, "event:::" + event.getAction());

if (event.getAction() == MotionEvent.ACTION_DOWN) {
     view.startAnimation(animRotate);
   view.setBackgroundResource(R.drawable.some_asset);
} else if (event.getAction() == MotionEvent.ACTION_UP ) {
    view.clearAnimation();
   view.setBackgroundResource(R.drawable.some_asset);
}

谢谢!

旋转视图的简单方法

Matrix matrix = new Matrix();
view.setScaleType(ScaleType.MATRIX);   //required 
matrix.postRotate((float) angle, pivX, pivY);
view.setImageMatrix(matrix);