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

문제

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?

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top