Android Scroll to Top of ScrollView with ListView and Other Child Views (Initial Jump Issue)

In my Android app, I was working in an Activity where I had a ScrollView containing a LinearLayout (could be a RelativeLayout too though) that had a few Views at the top followed by a ListView in the end that was long enough to move out of the bottom edge and add scrollbars to itself. Since I’d set a height to the ListView the ScrollView gained it’s vertical scrollbars.

The problem was that whenever the Activity loaded, the page would pre-scroll at the top of the ListView somewhere at 30% offset from the top. This was really annoying as everytime the page would load, the screen would jump at the ListView and I was unable to scroll to top to view the other Views defined previously in the layout file. Soon enough though, I found a solution in this StackOverflow thread – http://stackoverflow.com/q/4119441.

What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.

Hope it’ll help you out too! The solution that worked for me was this:

scrollView.smoothScrollTo(0, 0);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Author: Rishabh

Rishabh is a full stack web and mobile developer from India. Follow me on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *