简体   繁体   中英

Programmatically scroll to a view within a scrollview

I want to programmatically scroll a view within the scrollview. I can do this making:

 View viewToShow= ...
 ScrollView scrollView= ...;
 scrollView.scrollTo(0,viewToShow.getTop());

But it only works if the layout has been measured. The result of viewToShow.getTop() within onCreate() is 0 always, so it does not work.

How can I solve it? Thanks

override:

 public void onWindowFocusChanged (boolean hasFocus)

In this function, layout values are calculated (margin included)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM