Addev
Addev

Reputation: 32233

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

Upvotes: 0

Views: 104

Answers (1)

Sergey Vakulenko
Sergey Vakulenko

Reputation: 1667

override:

 public void onWindowFocusChanged (boolean hasFocus)

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

Upvotes: 1

Related Questions