ObjectAnimator with infinite rotation

I have an animator infinite_rotationthat is defined as:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:propertyName="rotation"
        android:repeatCount="infinite"
        android:valueFrom="0"
        android:valueTo="360"
        android:duration="2000" />
</set>

When the time (time is uncertain) comes that I no longer need it, I call infinite_animator.cancel(). Then run the fade_out animation in your layout container:

<set xmlns:android="http://schemas.android.com/apk/res/android">
        <objectAnimator
            android:propertyName="alpha"
            android:repeatCount="0"
            android:valueTo="0.0"
            android:duration="1000" />
</set>

The resulting animation is such that the rotation stops as expected, but stutters and then disappears. What am I missing?

Here's what it looks like:

enter image description here

UPDATE: I tested the above problem on an old Samsung Tab 4 with Kitkat OS. I just tested on the fairly new Samsung Tab 4 with Marshmallow OS. Animation works great. So I think the best question is how to fix inaccurate animations on my old device / OS?

This is the animation call:

private void animateRefreshButton() {
    ImageView iv_refresh = (ImageView) findViewById(R.id.iv_refresh);

    if(infinite_animator == null) {
        infinite_animator = AnimatorInflater.loadAnimator(this, R.animator.refresh_rotate);
    }
    infinite_animator.setTarget(iv_refresh);
    infinite_animator.start();
}

hideRefreshButton() , . :

private void hideRefreshButton() {
    if(infinite_animator != null) {
        infinite_animator.cancel();
    }

    Animator anim = AnimatorInflater.loadAnimator(this, R.animator.refresh_fadeout);
    anim.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {}

        @Override
        public void onAnimationEnd(Animator animation) {
            framelayout_container_of_iv_refresh.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {}

        @Override
        public void onAnimationRepeat(Animator animation) {}
    });
    anim.setTarget(framelayout_container_of_iv_refresh);
    anim.start();
}
+4
1

API - "" . API .

:


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        View view = findViewById(R.id.imageView);

        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, View.ROTATION, 0.0f, 360.0f);

        objectAnimator.setDuration(2000);
        objectAnimator.setRepeatCount(Animation.INFINITE);
        objectAnimator.setInterpolator(new LinearInterpolator());

        objectAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                view.animate()
                        .alpha(0.0f)
                        .setDuration(1000);
            }
        });

        objectAnimator.start();

        view.setOnClickListener((v) -> objectAnimator.cancel());

    }

:

enter image description here


(API 19): .

+5

Source: https://habr.com/ru/post/1685665/


All Articles