Search code examples
androidanimationscrollscrollviewobjectanimator

ObjectAnimator duration not respected


I'm trying to create an animation in order to scroll automatically in my scrollview.

LinearLayout linearLayout = (LinearLayout) scrollView.getChildAt(0);
// linearLayout.getHeight() == 540
animScroll = ObjectAnimator.ofInt(scrollView, "scrollY", linearLayout.getHeight());

// animationDurationLong == 154000
animScroll.setDuration(animationDurationLong);
animScroll.setInterpolator(new LinearInterpolator());

animScroll.start();

My animation is working perfectly, I scroll from the top of my scrollview content to the bottom BUT I do it in 96 seconds, instead of the 154 seconds set in duration.

Does anyone know why ? I check developer settings of my phone, tried on two devices, still the same problem.


Solution

  • your target "scrollY" is probably wrong (the last param of ofInt), you need something like this:

    height_of_content - height_of_container