NestedScrollView's smoothScrollTo() behaves weird

后端 未结 4 1244
半阙折子戏
半阙折子戏 2020-12-04 03:09

What I am trying to achieve is to scroll to scroll_position_1 when tab1 (and so on) is clicked like this. I don\'t understand what\'s happening at

4条回答
  •  孤城傲影
    2020-12-04 03:57

    Looks like there is a bug when programmatically scrolling NestedScrollView within CoordinatorLayout. This solved my problem:

    private void scrollToView(final View view) {
        mScroller.scrollBy(0, 1);
        mScroller.smoothScrollTo(0, view.getTop());
    }
    

    or for better control:

    private void scrollToView(final View view) {
        mScroller.scrollBy(0, 1);
        ObjectAnimator.ofInt(mScroller, "scrollY",  view.getTop()).setDuration(700).start();
    }
    

提交回复
热议问题