How to stop vertical auto scroll using ObjectAnimator?

Viewed 6

I have set vertical auto scroll for my text view in android studio , that works fine but the problem is i want to stop auto scroll with button click. this is the code i am using for auto scroll..

scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    ObjectAnimator objectAnimator = ObjectAnimator.ofInt(scrollView, "scrollY", scrollView.getChildAt(0).getHeight() - scrollView.getHeight());
                    objectAnimator.setDuration(150000);
                    objectAnimator.setInterpolator(new LinearInterpolator());
                    objectAnimator.start();
                }
            });

and this is what i have tried to stop auto scroll but nothing seems to work..

 ObjectAnimator animator = ObjectAnimator.ofInt(scrollView, "scrollY", scrollView.getChildAt(0).getHeight() - scrollView.getHeight());
            if (animator != null) {
                animator.removeAllListeners();
                animator.end();
                animator.cancel();
                animator.pause();
            }

please help ?

0 Answers
Related