Get the ViewTreeObserver of the ScrollView and add an OnGlobalLayoutListener to the ViewTreeObserver. Then call the ScrollView.scrollTo(x,y) method from the onGlobalLayout() method of the OnGlobalLayoutListener.
ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll);
ViewTreeObserver vto = scrollView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
mainScroll.scrollTo(0, 0);
}
});
Source. Courtesy - fahmy :)
However the catch here is that it takes position of the view to scroll to instead of its ID.
So you will have to find your views position first and then pass them as parameter to scrollTo. Use the below for getting the position,
View.getLocationOnScreen(int[] location);
this returns an integer array where (x = location[0] and y = location[1]). Here are docs for this method.