Programmatically scroll to the top of a NestedScrollView
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.
Another way to smooth scroll NestedScrollView
to all the way up or down is using fullScroll(direct)
function
nestedScrollView.fullScroll(View.FOCUS_DOWN);nestedScrollView.fullScroll(View.FOCUS_UP);