Search code examples
androidandroid-scrollview

Scrollview making view invisble


I have multiple views in my layout inside a ScrollView and there is a validation on certain items, in case of any error I scroll to that view using the following:

view.post(new Runnable() {
    @Override
    public void run() {
        view.scrollTo(0, view.getBottom());
        view.getParent().requestChildFocus(view, view);
    }
});

But the problem here is as soon as this code runs the scroll is achieved but the view passed to this makes itself invisible. After removing this everything is working fine.

I think this is some sort of bug with scrollview.


Solution

  • Your view is inside scrollView and you have added scrollTo() method in your view not in scrollView. Replace view.scrollTo(0,view.getBottom()) to scrollview.scrollTo(0, view.getBottom()). Try below solution this might work for you.

    view.post(new Runnable() {
        @Override
        public void run() {
            scrollview.scrollTo(0, view.getBottom());
            view.getParent().requestChildFocus(view, view);
        }
    });