安卓实现AppCompatImageView 动画 右上角为圆心 -90开始旋转 动画结束后图片反向正常
时间: 2024-02-29 09:52:52 浏览: 30
好的,你可以使用 Android 中的 ObjectAnimator 类来实现这个动画效果。
首先,你需要在布局文件中添加一个 AppCompatImageView,然后将其设置为要旋转的图片。
然后,在代码中创建一个 ObjectAnimator 对象,并设置其旋转属性为 rotation,设置旋转的起始值为 -90,结束值为 0,设置旋转的中心点为右上角。最后,使用 start 方法启动动画。
这是一个简单的代码示例:
```java
AppCompatImageView imageView = findViewById(R.id.image_view);
ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(imageView, "rotation", -90f, 0f);
rotationAnimator.setDuration(1000);
rotationAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
// 设置旋转中心点为右上角
imageView.setPivotX(imageView.getWidth());
imageView.setPivotY(0);
rotationAnimator.start();
```
如果想要在动画结束后图片反向正常,你可以添加一个监听器,在动画结束时将旋转角度设置为 0。如下:
```java
rotationAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
imageView.setRotation(0f);
}
});
```
这样就可以实现你的需求了。