为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Android中进行平滑的图像旋转?

如何在Android中进行平滑的图像旋转?

大话西游666 2019-12-07 16:23:43
我正在使用RotateAnimation旋转要用作Android中自定义循环微调器的图像。这是我的rotate_indefinitely.xml文件,放置在res/anim/:<?xml version="1.0" encoding="UTF-8"?><rotate    xmlns:android="http://schemas.android.com/apk/res/android"    android:fromDegrees="0"    android:toDegrees="360"    android:pivotX="50%"    android:pivotY="50%"    android:repeatCount="infinite"    android:duration="1200" />    当我将此应用到我的ImageViewusing时AndroidUtils.loadAnimation(),它很好用!spinner.startAnimation(     AnimationUtils.loadAnimation(activity, R.anim.rotate_indefinitely) );一个问题是,图像旋转似乎在每个循环的顶部暂停。换句话说,图像旋转360度,短暂暂停,然后再次旋转360度,依此类推。我怀疑问题在于动画使用的是默认插值器,如android:iterpolator="@android:anim/accelerate_interpolator"(AccelerateInterpolator),但我不知道如何告诉它不要插值动画。如何关闭插值(如果确实存在问题)以使动画循环流畅?
查看完整描述

3 回答

?
收到一只叮咚

TA贡献1821条经验 获得超4个赞

我也遇到了这个问题,并尝试在xml中设置线性插值器而没有成功。对我有用的解决方案是在代码中将动画创建为RotateAnimation。


RotateAnimation rotate = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

rotate.setDuration(5000);

rotate.setInterpolator(new LinearInterpolator());


ImageView image= (ImageView) findViewById(R.id.imageView);


image.startAnimation(rotate);


查看完整回答
反对 回复 2019-12-07
  • 3 回答
  • 0 关注
  • 440 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信