Search code examples
javaandroidanimationimageviewobjectanimator

ObjectAnimator Android is not working correctly on real device with API 19


I am making a game for Android and I encountered a problem while working on my next update. Game is set to work from API 19 upwards. I am using ObjectAnimator class to animate little bouncing arrows pointing buttons in tutorial. Nothing fancy.

Yellow arrow - Screenshot 1

Code:

 //Animate minestone clicker button arrow
            b1_animator = ObjectAnimator.ofFloat(button_minestone_pointer,"translationX",0,-100);
            b1_animator.setDuration(500);
            b1_animator.setRepeatMode(ValueAnimator.REVERSE);
            b1_animator.setRepeatCount(Animation.INFINITE);
            b1_animator.start();

Problem is, animations are smooth on ALL virtual devices provided by Android Studio (API 19 - API 27) and on all newer APIs, but on my phone (Sharp SH-01G), which is running Android 4.4, automatic scrolling or these arrows simply jump from one position to another creating blurred image. Did not have a chance to check it on another pre-API21 device yet. Feeling like it does not respect the ".setDuration();" bit. Scrolls are jumping immediately to the desired position but not smoothly at all.

This is the scroller code:

ObjectAnimator.ofInt(scroller_clickers, "scrollX",  800).setDuration(777).start();

So the question is, what is causing such a behaviour? I tried using view.animate() instead too, but it didn't help either. Clue is, when I tried to lookup the "getAnimatedFraction();" value, emulators were showing various fractions - smooth transition between 0.0 and 1. My phone was always showing 0.0 or 1.0 in somehow random order (Stuffed this into a TextView and refreshed with a Runnable). Assigning "AccelerateDecelerateInterpolator()" did not work either. I don't want to show a faulty game to the public :(

Any ideas?


Solution

  • Fixed. Turns out my phone had animations switched off from 1.0x to off in developer options which the ObjectAnimator class did not like. Works good now