RotateAnimation是Android中的动画效果之一,可以让View对象旋转一定角度。

使用RotateAnimation需要指定以下参数:

  1. fromDegrees:起始角度

  2. toDegrees:结束角度

  3. pivotX:旋转中心点的X坐标

  4. pivotY:旋转中心点的Y坐标

  5. duration:动画持续时间

以下是一个示例代码,将一个ImageView对象旋转180度:

ImageView iv = findViewById(R.id.iv);
RotateAnimation animation = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(1000);
animation.setFillAfter(true);
iv.startAnimation(animation);

在这个例子中,ImageView对象iv使用了RotateAnimation,将从0度旋转到180度,旋转中心点为自身中心点,动画持续时间为1秒。同时设置了FillAfter为true,表示动画结束后保持最后的状态。

通过修改参数,我们可以实现不同的旋转动画效果

AndroidStudio RotateAnimation旋转

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

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