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)
doesn't delegate the scroll events to the NestedScrollingParent
.
Use the View. scollTo(int x, int y) instead to scroll to the top.
NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
The problem can be solved by moving the SliverAppBar into the CustomScrollView and not use the NestedScrollView at all.
NestedScrollView.scrollTo(0, 0);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With