Android属性动画如何指定旋转动画的基准点?

例如对ImageView进行旋转,使用补间动画可以很方便的指定ImageView的pivotX和pivotY,示例代码如下:

RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees, pivotX, pivotY);
animation.setDuration(100);
animation.setFillAfter(true);
mArrowImg.startAnimation(animation);

但是使用属性动画,目前我知道可以这样实现:

ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(
                mArrowImageView, "rotate", fromDegress, toDegress);
objectAnimator.setDuration(100);
objectAnimator.start();

但是ObjectAnimator怎么指定pivotX和pivotY呢?

阅读 13.8k
2 个回答
mArrowImageView.setPivotX(10);//设置指定旋转中心点X坐标
mArrowImageView.setPivotY(10);//设置指定旋转中心点Y坐标

都是相对于View的坐标。

在进行属性动画之前,先对targetView设置pivotX和pivotY.

mArrowImageView.setPivotX(mArrowImageView.getMeasureWidth() / 2);
mArrowImageView.setPivotY(mArrowImageView.getMeasureHeight() / 2);
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(
                mArrowImageView, "rotate", fromDegress, toDegress);
objectAnimator.setDuration(100);
objectAnimator.start();
推荐问题