Sergey Shustikov
Sergey Shustikov

Reputation: 15821

How to know when scroll animation is finished?

I do a smooth scroll to defined position.

    smoothScrollTo(0, 1000);

After this method execute - i do a couple operations. But i want to do they - after scroll animation end.

I want to detect when scroll animation is finished. How i can do that?

Upvotes: 0

Views: 690

Answers (1)

MFP
MFP

Reputation: 1141

i have do like this,

    final ScrollView mScrollView = (ScrollView) findViewById(R.id.scrollview);
    layoutSponsorBax.setVisibility(View.VISIBLE);

    Timer timer = new Timer();

    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ViewGroup relativeL = (ViewGroup) mScrollView
                            .getChildAt(mScrollView.getChildCount() - 1);
                    final int sVH = mScrollView.getBottom()
                            - mScrollView.getTop();

                    View notePad = relativeL.getChildAt(2);
                    final int svHeight = 800;
                    Log.i("svHeight", "svHeight : " + svHeight);
                    final float duration = 2000;
                    ctt = new CountDownTimer((int) duration, 1) {
                        int temp = 0;


                        public void onTick(long millisUntilFinished) {
                            try {
                                Log.i("millisUntilFinished",
                                        "millisUntilFinished : "
                                                + millisUntilFinished);
                                Log.i("Height- Temp", "Temp : " + temp);
                                mScrollView.scrollTo(0, temp);
                                temp = (int) (((svHeight) - (millisUntilFinished / duration)
                                        * (svHeight)));
                            } catch (ArithmeticException e) {
                                e.printStackTrace();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        public void onFinish() {
                        }
                    }.start();
                }
            });
        }
    };
    int duration = 1400;
    timer.schedule(task, duration);

please check this it may be help to you

Upvotes: 2

Related Questions