您可以使用 ObjectAnimator 来实现这个旋转动画,并设置旋转的角度为 180 度,并保持旋转状态。

首先,在您的 XML 布局文件中添加一个 View,如 ImageView:

<ImageView
    android:id='@+id/imageView'
    android:layout_width='wrap_content'
    android:layout_height='wrap_content'
    android:src='@drawable/your_image' />

然后,在您的 Java 代码中,找到该 View 并创建旋转动画:

ImageView imageView = findViewById(R.id.imageView);
ObjectAnimator rotation = ObjectAnimator.ofFloat(imageView, 'rotation', 0f, 180f);
rotation.setDuration(1000); // 设置动画持续时间,单位为毫秒
rotation.setRepeatCount(ObjectAnimator.INFINITE); // 设置无限循环
rotation.setRepeatMode(ObjectAnimator.RESTART); // 设置循环模式为重新开始

rotation.start(); // 开始动画

这样,每次动画都会选择 180 度的旋转,并保持旋转状态。您可以根据需要调整动画的持续时间、循环次数和循环模式。

Android 旋转动画:实现180度旋转并持续循环

原文地址: https://www.cveoy.top/t/topic/fcNv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录