javaandroidanimationautoscroll

Object animator works only till the middle, not the bottom of scroll


Animation launches, but goes only till the particular spot somewhere in the middle of the scroll. What could cause such strange behavior? Please, help with some advice!

public void scrollAnimation() {
    // Scroll activity!
    final ScrollView mScrollView = (ScrollView) findViewById(R.id.myScrollViewID);
    mScrollView.post(new Runnable() {
        public void run()
        {
            ObjectAnimator anim = ObjectAnimator.ofInt(mScrollView, "scrollY", mScrollView.getBottom());
            anim.setDuration(3000);
            anim.start();
        }
    });
}

Solution

  • AnimatorSet animators = new AnimatorSet();
     int y = 8000; // pixels how far will go the scroll
    final ScrollView mScrollView = (ScrollView) findViewById(R.id.myScrollViewID);
    final ObjectAnimator yTranslate = ObjectAnimator.ofInt(mScrollView, "scrollY", y);
    animators.setDuration(100000L); // speed of scroll (greater the value -- greater the speed)
    
    animators.play(yTranslate);
    animators.start();