I solved this problem by implementing View.OnLayoutChangeListener in the fragment that controls my ScrollView.
public class YourFragment extends Fragment implements View.OnLayoutChangeListener{
...
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment view = inflater.inflate(R.layout.your_fragment_layout, container, false); //set scrollview layout change listener to be handled in this fragment sv = (ScrollView) view.findViewById(R.id.your_scroll_view); sv.addOnLayoutChangeListener(this); return view; }
...
public void onLayoutChange (View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom){ switch (v.getId()) { case R.id.your_scroll_view: { sv.scrollTo(0, sv.getTop()); } } }
source share