Is it possible to scroll the ScrollView that has vertical LinearLayout that has several TextViews (variable number) to the beginning of some TextView?

StackOverflow https://stackoverflow.com/questions/21703731

Question

I don't know if it's possible. I have a ScrollView, vertical LinearLayout child to it and I inflate programmatically array of TextViews on this vertical LinearLayout .

Now, let's say, I want to open this Activity with ScrollView scrolled to textView[4] Is that is possible to acheive?

Was it helpful?

Solution

Yes, you can use the following method:

scrollView.post(
    new Runnable() {
        @Override
        public void run() {
            new CountDownTimer(1500, 20) {
                @Override
                public void onTick(long millisUntilFinished) {
                    scrollView.scrollTo(0, (int) (textViewAbove.getBottom()-millisUntilFinished));
                }

               @Override
               public void onFinish() {                 
               }
            }.start();
        }
    }
);

Where textViewAbove is the TextView above the textView[4], textView[3] in that case.

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top