0

When I do a simple tween animation in a new project, regardless if I'm moving an image or a say a button, the animation is jerky / twitchy. On physical devices such as the S3 & RAZR.

Am I doing something wrong? Why would simple tween animations for moving a view in an IDE boilerplate app be twitchy / jerky on modern (4.x) devices?

public class MainActivity extends Activity {

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

    // called from a button's on click
    public void doImageAnimation(View view) {
            ImageView iv = (ImageView)findViewById(R.id.mciamge);
            iv.setY(200f);

            ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "x",1000);
            oa.setInterpolator(new LinearInterpolator());
            oa.setRepeatCount(5);
            oa.setDuration(3000l);
            oa.start();
    }

    // called from a button's on click
    public void doButtonAnimation(View view) {                
            Button iv = (Button)findViewById(R.id.mcbutton);
            iv.setX(0f);

            ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "x",1000);
            oa.setInterpolator(new LinearInterpolator());
            oa.setRepeatCount(5);
            oa.setDuration(3000l);
            oa.start();
    }        

}
McNinja
  • 798
  • 7
  • 19
  • 1
    Have you tried speeding up the duration? If you have an animation that's too slow, it can seem kinda choppy because it'll move a single pixel every x milliseconds. Other factors are the complexity of the bitmaps on the views and how many views are in the hierarchy. – DeeV Feb 13 '14 at 19:37
  • I haven't tried speeding up the duration. The animation needs to move slow, as I need to copy what was done on the iOS version of this app :( – McNinja Feb 13 '14 at 19:48
  • 1
    Instead of speeding up the animation, try increasing the range of pixels to move. Currently you're moving 1000 pixels over 3 seconds which amounts to about 63 pixels every 250 ms. On a high res device, this is very small distance while on a high res device, it's quite far which will also look "choppy". Convert the pixels to DP pixels based on your device. – DeeV Feb 13 '14 at 19:54
  • DeeV, what you said sounds promising. But I don't know how to do what you're saying. How do I do that with ObjectAnimator? – McNinja Feb 13 '14 at 20:48
  • 1
    http://stackoverflow.com/questions/4605527/converting-pixels-to-dp Get the pixels from that and replace the "1000" with the result. If it does work, I'll convert all this to an answer. – DeeV Feb 13 '14 at 21:13
  • Hmmmm...so I'm looking at top for the amount of processor power this is taking. 11-15% CPU on Droid Razr, 8-11% CPU on Galaxy S3. The DP -> pixels...I still end up with a pixel value I need to give as an argument to the ObjectAnimator. However you did give me a idea! The _less_ distance moved, the less choppy movement and less CPU used. So I had values moving too far & now they're not as choppy when they don't move as far. So like you said, quite far! Thank you! – McNinja Feb 17 '14 at 14:55

0 Answers0