0

I want the toolbar and imageview to collapse, when the user scrolls up. Since I'm not using a recyclerview, a suggested workaround was to wrap the imageview in a NestedScrollView.

All of the content below the AppBarLayout, is made up of imageviews, textviews, and many kinds of layouts. By default such content does not scroll, so I wrapped it in a NestedScrollView. This makes the content scroll-able. the problem is, that scrolling up now only makes the bottom NestedScrollView move, and the toolbar does not collapse.

  <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.solidcolorlabs.android.solid.activities.ExampleActivity">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="200dp">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <android.support.v4.widget.NestedScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    app:layout_collapseMode="parallax"
                    app:layout_scrollFlags="scroll">

                        <ImageView
                            android:id="@+id/venue_image"
                            android:layout_width="match_parent"
                            android:layout_height="200dp" />

                </android.support.v4.widget.NestedScrollView>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?android:attr/actionBarSize"
                    android:minHeight="?attr/actionBarSize"
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    app:layout_collapseMode="pin"
                    app:navigationContentDescription="@string/abc_action_bar_up_description"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                </android.support.v7.widget.Toolbar>

            </android.support.design.widget.CollapsingToolbarLayout>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layout_collapseMode="parallax"
            app:layout_scrollFlags="scroll">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                      ...

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>

    </LinearLayout>
HaloMediaz
  • 1,251
  • 2
  • 13
  • 31

1 Answers1

0

Change LinearLayout to CoordinatorLayout.

Jack Lynx
  • 216
  • 2
  • 12