如何使Android中的平滑图像旋转? [英] How to make a smooth image rotation in Android?

查看:194
本文介绍了如何使Android中的平滑图像旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个 RotateAnimation 旋转,我使用在Android的定制周期微调的图像。这是我的 rotate_indefinitely.xml 文件,我放在 RES /动画/

I'm using a RotateAnimation to rotate an image that I'm using as a custom cyclical spinner in Android. Here's my rotate_indefinitely.xml file, which I placed in 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" />

当我将此运用到我的的ImageView 使用 AndroidUtils.loadAnimation(),它的伟大工程!

When I apply this to my ImageView using AndroidUtils.loadAnimation(), it works great!

spinner.startAnimation( 
    AnimationUtils.loadAnimation(activity, R.anim.rotate_indefinitely) );

该一个问题是,图像旋转似乎暂停在每个周期的顶部。

The one problem is that the image rotation seems to pause at the top of every cycle.

在换句话说,图像旋转360度,短暂暂停,然后再次旋转360度,等等。

In other words, the image rotates 360 degrees, pauses briefly, then rotates 360 degrees again, etc.

我怀疑的问题是,动画是使用默认的内插像安卓iterpolator =@机器人:动画/ accelerate_interpolator AccelerateInterpolator ),但我不知道该怎么告诉它不要插动画。

I suspect that the problem is that the animation is using a default interpolator like android:iterpolator="@android:anim/accelerate_interpolator" (AccelerateInterpolator), but I don't know how to tell it not to interpolate the animation.

我如何关闭插值(如果这确实是问题),使我的动画循环顺畅?

How can I turn off interpolation (if that is indeed the problem) to make my animation cycle smoothly?

推荐答案

您是对的AccelerateInterpolator;你应该使用LinearInterpolator代替。

You are right about AccelerateInterpolator; you should use LinearInterpolator instead.

您可以使用内置的 android.R.anim.linear_interpolator 从您的动画XML文件安卓插=@机器人:动画/ linear_interpolator

You can use the built-in android.R.anim.linear_interpolator from your animation XML file with android:interpolator="@android:anim/linear_interpolator".

或者你可以在你的项目中,如创建自己的XML文件插值它命名为 RES /动画/ linear_interpolator.xml

Or you can create your own XML interpolation file in your project, e.g. name it res/anim/linear_interpolator.xml:

<?xml version="1.0" encoding="utf-8"?>
<linearInterpolator xmlns:android="http://schemas.android.com/apk/res/android" />

和添加到您的动画XML:

And add to your animation XML:

android:interpolator="@anim/linear_interpolator"

特别提示::如果您旋转的动画是一家集里面,设置插补器似乎不工作。制作的顶级元素修复它的旋转。 (这将节省您的时间。)

Special Note: If your rotate animation is inside a set, setting the interpolator does not seem to work. Making the rotate the top element fixes it. (this will save your time.)

这篇关于如何使Android中的平滑图像旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆