Programmatically scroll to the top of a NestedScrollView

后端 未结 13 1654
情书的邮戳
情书的邮戳 2020-12-13 12:02

Is there a way to programmatically scroll to the top of a NestedScrollView by also triggering the scroll events for the parent? smoothScrollTo(x, y)

13条回答
  •  醉话见心
    2020-12-13 12:29

    I managed to do it (animated scrolling):

    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
    AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
    if (behavior != null) {
        behavior.onNestedFling(coordinatorLayout, appBarLayout, null, 0, 10000, true);
    }
    

    where 10000 is the velocity in y-direction.

提交回复
热议问题