I have CoordinatorLayout and following items inside it:
- AppBarLayout with collapsable toolbar;
- NestedScrollView with some content
I want to programmatically scroll my NestedScrollView up until Collapsable Toolbar is collapsed.
I tried the code like this:
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
if (behavior != null) {
behavior.onNestedPreScroll(coordinatorLayout, appBarLayout, nestedScrollView, 0, 1000, new int[2]);
}
But it just scrolls up and collapses the AppBar layout itself and NestedScrollView remains on its place.
So,the question is how to scroll NestedScrollView up and made Collapsable Toolbar to collapse?
I know the issue related somehow with Coordinator Layout's behavior, but I can't realize what is missed.
Here is the exact layout:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/event_coordinator_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!-- some content -->
<android.support.v7.widget.Toolbar
android:id="@+id/quick_return_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- some content -->
</android.support.v4.widget.NestedScrollView>