Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

When I close the navigation drawer the scroll view moves down

When I close the navigation drawer the scroll view moves down. For example, if the current positionY is at the top of the scrollView, when I close the scroll view it moves it down to the middle/ near bottom. I tried doing this onCreate:

ViewTreeObserver vto = scrollView.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                scrollView.scrollTo(scrollX, scrollY);
            }
        });

Although it works, 1. it doesn't go to the right position, 2. it doesn't do it right away. I can see it quickly goes down, and then it scrolls it up again. It is like a flash of it going up and down

1 Answer

I found the answer. I have a relative layout below the scroll view and put

android:descendantFocusability="blocksDescendants"

Now it works