How to set the starting position of a ScrollView?

后端 未结 6 1512
野趣味
野趣味 2021-01-07 23:36

I have been trying to set the initial position of a scroll View but have not found a way. Does anyone have any ideas? Also I have a GoogleMaps fragment as a children of the

6条回答
  •  执念已碎
    2021-01-08 00:01

    The accepted answer is not working for me. There is no direct way to set the initial position of a scroll view.

    However, you can set the initial position before drawing the scroll view, like this:

    rootView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            scrollView.getViewTreeObserver().removeOnPreDrawListener(this);
            scrollView.setScrollY(100);
            return false;
        }
    });
    

    You can also use scrollView.setScrollY(100) inside Handler, but that will be jerky while scrolling.

提交回复
热议问题