Why there is easing effect on my rotating animatio

2019-07-29 21:49发布

问题:

I'm trying to develop my first Android app. I read a lots of article about animations. Now there is a ImageView on my layout and i want to rotate it 360 degrees. And this animation repeat forever. So here is my solteypanim.xml file :

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:ordering="sequentially" >
    <objectAnimator
    android:duration="3000"
        android:propertyName="rotation"
        android:repeatCount="infinite"
        android:valueTo="360"
        android:valueFrom="0" />
</set>

And this is my activity code

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    ...    
    ImageView solTeyp = (ImageView)findViewById(R.id.solTeyp);
    AnimatorSet solTeypAnim = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.solteypanim);
    solTeypAnim.setTarget(solTeyp);
    solTeypAnim.start();
    ...
    }

It's working BUT there is a problem. Changing of rotation's value not linear. I mean there is a easing effect at start and end of animation. It's starting slowly, and then getting speed, and decreasing speed. There is same problem for every turn.

Can you tell me how can i disable this easing effect ?

回答1:

OK just found answer. I should set linear interpolator to my objectAnimator , not my set .

Like this :

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:ordering="sequentially" >
    <objectAnimator
    android:duration="3000"
    android:interpolator="@android:anim/linear_interpolator"
        android:propertyName="rotation"
        android:repeatCount="infinite"
        android:valueTo="360"
        android:valueFrom="0" />
</set>