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

我正在使用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),但我不知道如何告诉它不要插值动画。


如何关闭插值(如果确实存在问题)以使动画循环流畅?


大话西游666
浏览 538回答 3
3回答

收到一只叮咚

我也遇到了这个问题,并尝试在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);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android